Hi,
Today I am going to give you a simple C++ program. This following program structures display
the name of the week, depending upon the number entered through the keyboard
using the switch-case statement. The
switch statement is a special multi way decision maker that tests whether an
expression matches one of the numbers of constant values, and braces accordingly.
However,
Type this following code on Turbo C++ and run your program.
// A program to display the name of the week, depending upon the number entered through the keyboard
#include <iostream.h>
void main (void)
{
int day;
cout << "Enter a number between 1 to 7 \n";
cin >>day;
switch (day) {
case 1 :
cout <<"Monday \n";
break;
case 2 :
cout <<"Tuesday \n";
break;
case 3 :
cout <<"Wednesday \n";
break;
case 4 :
cout <<" Thursday \n";
break;
case 5 :
cout <<" Friday \n";
break;
case 6 :
cout <<" Saturday \n";
break;
case 7 :
cout <<" Sunday \n";
break;
} // end of switch statement
} // end of main program
Output of the above program:
Enter a number between 1 to 7
4
Thursday
If you face any problem please inform us by commenting. We always ready to serve you.
Thanks!
No comments:
Post a Comment