Deciding the day of week using switch-case construct in C++
Program :-
#include<iostream.h>
void main()
{
int day:
cout<<"Enter the number in between of 1 to 7 to get corresponding day :";
cin>>day;
switch(day)
{
case 1: cout<<"Today is Sunday";
break;
case 2: cout<<"Today is Monday";
break;
case 3: cout<<"Today is Tuesday";
break;
case 4: cout<<"Today is Wednesday";
break;
case 5: cout<<"Today is Thursday";
break;
case 6: cout<<"Today is Friday";
break;
case 7: cout<<"Today is Saturday";
break;
default : cout<<"Not a valid day";
break;
}
}
Output :-
Enter the numberin betweeen of 1 to 7 to get corresponding day :
3
Today is Tuesday
IF THE NUMBER IS NOT BETWEEN 1 TO 7 THE OUT PUT WILL BE
" Not a valid day "
Comments
Post a Comment