Switch with default in C++
Level 3129 keystrokes
day is 5, which matches neither case 1 nor case 2, so the default branch runs and prints "Other".
C++ code
1int day = 5;// Compares day with each case label2switch (day) { // Not 1 or 2, so these cases are skipped3 case 1: cout << "Mon"; break;4 case 2: cout << "Tue"; break; // default catches every other value: prints Other5 default: cout << "Other";6}// The cases print without endl, so the line ends here7cout << endl;Output
Other
Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this C++ code and how often they appear.
<× 8;× 7"× 6:× 3(× 1)× 1{× 1}× 1=× 1