Simple Switch
Source Code
|
|
Run Output
Code Understanding
This program displays the day of the week based on the number entered by the user using a switch statement.
• int d; declares a variable to store the day number.
• cin >> d; takes input from the user.
• switch(d) checks the value of d and executes the corresponding case:
o 1 → Monday
o 2 → Tuesday
o 3 → Wednesday
o 4 → Thursday
o 5 → Friday
o 6 or 7 → HOLIDAY (both weekend days)
• default handles any invalid input (numbers not 1-7).
• break; ensures only the matching case runs.
Created: 1-Mar-2026 16:56 | Updated: 19-Apr-2026 18:46|
