The correct answer is: B. Conditions not in brackets
The if-else statement is a control flow statement that allows you to execute a block of code if a condition is true, or another block of code if the condition is false. The syntax for an if-else statement is as follows:
if (condition) {
// code to execute if condition is true
} else {
// code to execute if condition is false
}
In the given example, the condition is intQuantity > 5
. However, the condition is not enclosed in brackets. This is a syntax error, and the program will not compile.
The following is the correct syntax for the if-else statement:
if (intQuantity > 5) {
dblDiscountRate = .1;
} else {
dblDiscountRate = .05;
}
The other options are not correct. Option A is incorrect because there is no error in the code. Option C is incorrect because there is a semicolon after the Else
statement. Option D is incorrect because the spelling of Then
is correct.