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
Post A Comment:
0 comments: