# Subgoals

## Section4.9Assessment: Sequential If-Statements

### Subgoals for Evaluating Selection Statements.

1. Diagram which statements go together
2. For if statement, determine whether expression is true or false
3. If true ߝ follow true branch, if false ߝ follow else branch or do nothing if no else branch

### ExercisesExercises

#### 1.

Q1: A game has a series of three levels, but you only get the bonus points if you pass all three levels on the first try. Assume the following declarations:
boolean level1, level2, level3;
The variables indicate whether the level was passed on the first try (true indicates yes, false indicates no).
Which of the following code segments will properly update the points variable?
1. if (level1 && level2 && level3)
points += 5;

2. if (level1 || level2 || level3)
points += 5;

3. if (level1)
points += 5;
if (level2)
points += 5;
if (level3)
points += 5;

• I only
• II only
• III only
• I and III
• II and III

#### 2.

Q2: A company offers a discount depending on the number of units of the product that are ordered:
Assume that the variables numUnits, discount have been declared and have values.
Which of the following code segments will work as intended?
1. if (numUnits >= 50)
discount = 0.2;
if (numUnits >= 10)
discount = 0.1;
if (numUnits > 0)
discount = 0;

2. if (numUnits >= 50)
discount = 0.2;
else if (numUnits >=10)
discount = 0.1;
else
discount = 0;

3. if (numUnits > 0)
discount = 0;
if (numUnits > 10)
discount = 0.1;
if (numUnits > 50)
discount = 0.2;

• I only
• II only
• III only
• I and III
• II and III