Complete the code to print "One" when the variable num is 1.
int num = 1; switch (num) { case [1]: std::cout << "One" << std::endl; break; default: std::cout << "Other" << std::endl; }
The case label must match the value of num to execute the correct block. Here, case 1: matches num = 1.
Complete the if statement to print "Two" when num equals 2.
int num = 2; if (num [1] 2) { std::cout << "Two" << std::endl; } else { std::cout << "Not Two" << std::endl; }
The equality operator == checks if num is equal to 2.
Fix the error in the switch statement to correctly handle the variable grade.
char grade = 'B'; switch (grade) { case [1]: std::cout << "Good" << std::endl; break; default: std::cout << "Other grade" << std::endl; }
Character constants in C++ use single quotes. Double quotes are for strings.
Fill both blanks to create a map from numbers to words using if statements.
int num = 3; if (num [1] 1) { std::cout << "One" << std::endl; } else if (num [2] 3) { std::cout << "Three" << std::endl; } else { std::cout << "Other" << std::endl; }
Use the equality operator == to check if num equals 1 or 3.
Fill all three blanks to create a switch statement that prints the day of the week for 1, 2, and 3.
int day = 2; switch (day) { case [1]: std::cout << "Monday" << std::endl; break; case [2]: std::cout << "Tuesday" << std::endl; break; case [3]: std::cout << "Wednesday" << std::endl; break; default: std::cout << "Other day" << std::endl; }
The case labels must match the values 1, 2, and 3 to print the correct day.
