# Subgoals

## Section6.6Assessment: Writing Selection Statements

### Subgoals for Writing Selection Statements.

If Statement
1. Define how many mutually exclusive paths are needed
2. Order from most restrictive/selective group to least restrictive
3. Write if statement with Boolean expression
4. Follow with true bracket including action
6. Repeat until all groups and actions are accounted for
OR Switch Statement
1. Determine variable / expression for mutually exclusive ranges
2. Write switch statement based on variable / expression
3. Each range is a ‘case’
4. Include break statements and default case if needed

### ExercisesExercises

#### 1.

Q1: Which of the following boolean expressions is appropriate to test if the age of a person is at least 18 and their weight is no more than 20 kilograms?
• age > 18 && weight > 20
• age < 18 && weight > 20
• age >= 18 && weight >= 20
• age >= 18 || weight < 20
• age >= 18 && weight <= 20

#### 2.

Q2: Given the following problem statement, what order should the following conditions be placed in?
Problem: Any score that is less than 50 is considered outstanding. Any score that is 100 or more is considered invalid. Any score that is at least 50 less than 100 is acceptable.
Condition 1: if (score < 50)
Condition 2: if (score >= 100)
Condition 3: if (score > 50 && score < 100)
• 1 then 2 then 3
• 2 then 1 then 3
• 3 then 2 then 1
• 3 then 1 then 2
• 1 then 3 then 2
• The order does not matter

#### 3.

Q3: Which of the following pieces of code correctly solves the problem?