C++ Program Codes for a Four-function Calculator


#include<iostream.h>
int main()
{
char ch;
float a,b,result;
cout<<"\n\t Enter two numbers:";
cin>>a>>b;
cout<<"\n\t"<<"Enter the Operator(+,-,*,/):";
cin>>ch;
cout<<"\n\t";
if(ch=='+')
result=a+b;
else if(ch=='-')
result=a-b;
else if(ch=='*')
result=a*b;
else if(ch=='/')
result=a/b;   // b must not be zero
else
cout<<"Wrong Operator!!\n";
cout<<"\n"<<"The Calculated Result is:"<<result<<"\n";
return 0;
}

Labels: , , , , ,