#include<iostream.h>
#include<conio.h>
void main()
{
float op1,op2,res;
char ch;
clrscr();
cout<<"Enter two numbers:";
cin>>op1>>op2;
cout<<"\n"<<"Enter an Operator (+,-,*,/,%)";
cin>>ch;
cout<<"\n";
switch (ch)
{
case'+':res=op1+op2;
break;
case'-':res=op1-op2;
break;
case'*':res=op1*op2;
break;
case'/': if(op2==0)
cout<<"Divide by Zero error!!!";
else
res=op2/op1;
break;
case'%': if(op2==0)
cout<<"Divide by Zero error!!!";
else
{
int r,q;
q=op2/op1;
r=op2-(q*op1);
res=r;
} //end of else
break;
default:cout<<"\n"<<"Wrong Operator!!!";
}
cout<<"The Calculated Result is:"<<res<<"\n";
getch();
}
No comments:
Post a Comment