C++ Program to perform all arithmetic calculation using switch case

#include<iostream.h>
#include<conio.h>

void main()
{
clrscr();
float a,b,res;
int ch,q;
cout<<“Arithmetic Operatios”;
cout<<“nn1.Additionn2.Subtractionn3.Multiplicationn4.Divisionn5.Mode”;
cout<<“n  Enter your choice:”;
cin>>ch;

switch(ch)
{
case 1:
{
cout<<“nnEnter two variables:”;
cin>>a>>b;
res=a+b;
cout<<“n  Result=”<<res;
}
break;

case 2:
{
cout<<“nnEnter two variables:”;
cin>>a>>b;
res=a-b;
cout<<“n  Result=”<<res;
}
break;

case 3:
{
cout<<“nnEnter two variables:”;
cin>>a>>b;
res=a*b;
cout<<“n  Result=”<<res;
}
break;

case 4:
{
cout<<“nnEnter two variables:”;
cin>>a>>b;
if(a>=b)
{
res=a/b;
cout<<“n  Result=”<<res;
}
else
cout<<“nnt1st varable should be greater than 2nd.!!!”;
}
break;

case 5:
{
cout<<“nnEnter two variables:”;
cin>>a>>b;
if(a>=b)
{
q=a/b;
res=a-(b*q);
cout<<“n  Result=”<<res;
}
else
cout<<“nnt1st variable should be greater than 2nd..!!!”;
}
break;
}

getch();
}

One thought on “C++ Program to perform all arithmetic calculation using switch case

Leave a Reply

Your email address will not be published. Required fields are marked *