Â
In this, we are going to see the topic of Switch case in C++.
This is a of Switch Case in which we are going to just print the user input.
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";
char val;
cout<<"Enter a letter from 'a' to 'e' to select the case\n";
cin>>val;
switch (val)
{
case 'a':
cout<<"You entered alphabet a \n";
break;
case 'b':
cout<<"You entered alphabet b \n";
break;
case 'c':
cout<<"You entered alphabet c \n";
break;
case 'd':
cout<<"You entered alphabet d \n";
break;
case 'e':
cout<<"You entered alphabet e \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";
char val;
cout<<"Enter a letter from 'a' to 'e' to select the case\n";
cin>>val;
switch (val)
{
case 'a':
cout<<"You entered alphabet a \n";
break;
case 'b':
cout<<"You entered alphabet b \n";
break;
case 'c':
cout<<"You entered alphabet c \n";
break;
case 'd':
cout<<"You entered alphabet d \n";
break;
case 'e':
cout<<"You entered alphabet e \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