Example of Switch Statement
#include<iostream.h>
#include<conio.h>void main()
{
clrscr();
float a,b,r;
char ch;
cout<<"Enter First Number :\t";
cin>>a;
cout<<"Enter Second Number :\t";
cin>>b;
cout<<"Enter operator (+,-,*,/,%) :\t";
cin>>ch;
cout<<"\n";
switch (ch)
{
case '+': r=a+b;
cout<<"\n Adding :\t"<<r;
break;
case '-': r=a-b;
cout<<"\n Subtracting :\t"<<r;
break;
case '*': r=a*b;
cout<<"\n Multipling :\t"<<r;
break;
case '/': if(b==0)
cout<<"\nDivide by ZERO";
else
r=b/a;
cout<<"\n Dividing :\t"<<r;
break;
case '%': if(b==0)
cout<<"\nDivide by ZERO";
else
{
int res,q;
q=b/a;
res=b - (q*a);
res=r;
cout<<"\n Modulus :\t"<<r;
}
break;
default : cout<<"\nCheck your CHOICE";
}
getch();
}