Final answer:
To convert the given conditional statement to a switch statement, follow these steps: identify the condition, create a switch statement, add cases for each value, include code for each case, and add a default case. Here's the converted switch statement.
Step-by-step explanation:
To convert the given conditional statement to a switch statement, you can use the following steps:
- Identify the condition in each if statement and assign it to a variable.
- Create a switch statement with the variable as the expression.
- Add cases for each possible value of the variable.
- Include the appropriate code for each case.
- Add a default case for any values that don't match the cases.
Here's the converted switch statement:
switch (numBooks) {
case 0:
case 1:
case 2:
cout << "You earned 0 points.\\";
break;
case 4:
cout << "You earned 5 points.\\";
break;
default:
cout << "That's an invalid number of books.\\";
}