int day = 3;
switch (day) {
case 1: cout << "Monday"; break;
case 2: cout << "Tuesday"; break;
case 3: cout << "Wednesday"; break;
default: cout << "Other"; break;
}
// Output: Wednesday
Always end each case with break; — without it, execution falls through to the next case.
switch (month) {
case 1: case 3: case 5: case 7:
case 8: case 10: case 12:
return 31;
case 4: case 6: case 9: case 11:
return 30;
default: return 28;
}
Write dayName(int d) that returns the day name for 1–7 (Monday–Sunday), or "unknown" for anything else.
Click "Run" to execute your code.