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 label
2switch (day) {
// Not 1 or 2, so these cases are skipped
3 case 1: cout << "Mon"; break;
4 case 2: cout << "Tue"; break;
// default catches every other value: prints Other
5 default: cout << "Other";
6}
// The cases print without endl, so the line ends here
7cout << endl;

Output

Other
Practice typing this code

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

More C++ examples at level 3

← C++ typing practice