When a decision matches one integer or character against several exact values, a switch statement can make the alternatives easy to scan. It is a selection tool, not a replacement for every range comparison.
#include <iostream>
#include <string>
int main() {
int roomCode = 3;
std::string room = "Pending";
switch (roomCode) {
case 1:
room = "Kitchen";
break;
case 3:
room = "Studio";
break;
default:
room = "Reception";
break;
}
std::cout << room << "\n";
return 0;
}
switch (roomCode) evaluates the selection value. A case label names an exact value followed by a colon. Here execution begins at case 3, assigns "Studio", and reaches break. The break exits the switch so execution continues at the output statement.
Without that break, execution can continue into the following case or default statements. This is called fallthrough. For these independent choices, each branch should stop after setting its result. The default label provides a fallback when no case matches; it does not need a comparison.
Use if chains for ranges such as “less than eighteen.” Use this form of switch for discrete integer or character choices; a std::string is not a supported switch condition.
The starter selects session code 2, but has no matching case yet, so it reaches the fallback. Add your case at the TODO before default. It needs a label, an assignment to session, and a break to keep the fallback from overwriting that assignment. Leave the supplied case and default branch in place.
case 2 to assign "Craft table" to session, ending that case with break;. Expect Session: Craft table.Edit main.cpp, press Run to inspect the Console, then Submit to check these results.