AI Features

Solution Review: Display Day of the Week

Let's see the detailed solution review of the challenge given in the previous lesson.

We'll cover the following...

Solution

Run the code below and see the output!

C++
#include <iostream>
using namespace std;
int main() {
// Initialize variable number
int number = 3;
// switch block
switch (number) {
// first case
case 1:
cout << "Monday";
break;
// second case
case 2:
cout << "Tuesday";
break;
// third case
case 3:
cout << "Wednesday";
break;
// fourth case
case 4:
cout << "Thursday";
break;
// fifth case
case 5:
cout << "Friday";
break;
// sixth case
case 6:
cout << "Saturday";
break;
// seventh case
case 7:
cout << "Sunday";
break;
// default case
default:
cout << "Invalid input";
}
return 0;
}
...