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

Program

#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();
}

Leave a Comment

error: Alert: Content is protected!!