In this, we are going to see the topic of Switch case in C++.
This is a program of Switch Case in which we are going to print the months from 1 to 12 by taking the value from user i.e. User input value
The code given below can be used for TURBO C++ Compiler:-
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
cout<<"\n **** This Program is of Switch Case **** \n";
int week_day;
cout<<"Enter a number to select the Month\n";
cin>>week_day;
switch (week_day)
{
case 1:
cout<<"This Month is January\n";
cout<<"This Month is of Winter Season\n";
break;
case 2:
cout<<"This Month is February\n";
cout<<"This Month is of Summer Season\n";
break;
case 3:
cout<<"This Month is March\n";
cout<<"This Month is of Summer Season\n";
break;
case 4:
cout<<"This Month is April\n";
cout<<"This Month is of Summer Season\n";
break;
case 5:
cout<<"This Month is May\n";
cout<<"This Month is of Summer Season\n";
break;
case 6:
cout<<"This Month is June\n";
cout<<"This Month is of Rainy Season\n";
break;
case 7:
cout<<"This Month is July\n";
cout<<"This Month is of Rainy Season\n";
break;
case 8:
cout<<"This Month is August\n";
cout<<"This Month is of Rainy Season\n";
break;
case 9:
cout<<"This Month is September\n";
cout<<"This Month is of Rainy Season\n";
break;
case 10:
cout<<"This Month is October\n";
cout<<"This Month is of Winter Season\n";
break;
case 11:
cout<<"This Month is November\n";
cout<<"This Month is of Winter Season\n";
break;
case 12:
cout<<"This Month is December\n";
cout<<"This Month is of Winter Season\n";
break;
default:
cout<<"Oops!! Your input is not accepted.\n";
cout<<"Please read the instructions carefully\n";
break;
}
cout<<"Thank You !!";
getch();
}
The code given below can be used for g++/gcc Compiler:-
#include<iostream>
using namespace std;
int main()
{
cout<<"\n **** This Program is of Switch Case **** \n";
int week_day;
cout<<"Enter a number to select the Month\n";
cin>>week_day;
switch (week_day)
{
case 1:
cout<<"This Month is January\n";
cout<<"This Month is of Winter Season\n";
break;
case 2:
cout<<"This Month is February\n";
cout<<"This Month is of Summer Season\n";
break;
case 3:
cout<<"This Month is March\n";
cout<<"This Month is of Summer Season\n";
break;
case 4:
cout<<"This Month is April\n";
cout<<"This Month is of Summer Season\n";
break;
case 5:
cout<<"This Month is May\n";
cout<<"This Month is of Summer Season\n";
break;
case 6:
cout<<"This Month is June\n";
cout<<"This Month is of Rainy Season\n";
break;
case 7:
cout<<"This Month is July\n";
cout<<"This Month is of Rainy Season\n";
break;
case 8:
cout<<"This Month is August\n";
cout<<"This Month is of Rainy Season\n";
break;
case 9:
cout<<"This Month is September\n";
cout<<"This Month is of Rainy Season\n";
break;
case 10:
cout<<"This Month is October\n";
cout<<"This Month is of Winter Season\n";
break;
case 11:
cout<<"This Month is November\n";
cout<<"This Month is of Winter Season\n";
break;
case 12:
cout<<"This Month is December\n";
cout<<"This Month is of Winter Season\n";
break;
default:
cout<<"Oops!! Your input is not accepted.\n";
cout<<"Please read the instructions carefully\n";
break;
}
cout<<"Thank You !!";
return 0;
}
#ENJOY CODING
Â
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP