Example of Switch case statement without using the break in C++:

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"; 
case  2: cout<<"Today is Tuesday"; 
case  3: cout<<"Today is Wednesday"; 
case  4: cout<<"Today is Thursday"; 
case  5: cout<<"Today is Friday"; 
case  6: cout<<"Today is Saturday"; 
case  7: cout<<"Today is Sunday"; 
default: cout<<"Only enter value 1 to 7";


}
}

Program output is tested on www.jdoodle.com

input: 

Enter any number (1 to 7)

4

output:
Today is Thursday
Today is Friday
Today is Saturday
Today is Sunday
Only enter value 1 to 7


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: