Example of Switch Case program in C++ Language:

The switch is multiple conditional statements in C++ language and further used to execute the code from multiple conditions or case. This is also same as if-else-if ladder statement. This statement work with byte, short, int, char and primitive, enumerated data types and with string also.

#include <iostream>
using namespace std;
int main()
{
int n;
cout<<"Enter any number (1 to 7)";
cout<<endl;
cin>>n;
switch(n)
{
case  1: cout<<"Today is Monday"; break;
case  2: cout<<"Today is Tuesday"; break;
case  3: cout<<"Today is Wednesday"; break;
case  4: cout<<"Today is Thursday"; break;
case  5: cout<<"Today is Friday"; break;
case  6: cout<<"Today is Saturday"; break;
case  7: cout<<"Today is Sunday"; break;
default: cout<<"Only enter value 1 to 7";
}
}



Program output is tested on www.jdoodle.com

input: 

Enter any number (1 to 7)

6
output:
Today is Saturday




Thanks
Mukesh Rajput
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: