This C++ program takes an input of a day's number and uses a switch statement to output the corresponding day's name. Here's how the program works:
Overall, this program is a good example of how to use a switch statement in C++ to handle multiple cases. However, it could be improved by adding input validation to check that the entered day number is within the correct range of 1 to 7. Additionally, it could be modified to handle upper case letters, or to output a message if an invalid input is entered.
#include<iostream> using namespace std; int main() { int day; cout<<"\nEnter the Day's number :"; cin>>day; switch (day) { case 1: cout<<"Monday"; break; case 2: cout<<"Tuesday"; break; case 3: cout<<"Wednesday"; break; case 4: cout<<"Thursday"; break; case 5: cout<<"Friday"; break; case 6: cout<<"Saturday"; break; case 7: cout<<"Sunday"; break; } return 0; }To download raw file Click Here
Enter the Day's number :3 Wednesday
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions