PROGRAM
Program to create the equivalent of a four-function calculator.The program requires the user to enter two numbers and an operator.It then carries out the specified arithmetic operation:addition,subtraction,multiplication or division of two numbers.Finally,it displays the result.#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
int main()
{
system ("cls");
char ch;
float a,b,result;
cout<<"Enter two numbers:";
cin>>a>>b;
cout<<"\n"<<"Enter the operator(+,-,*,/):";
cin>>ch;
cout<<"\n";
if(ch=='+')
result=a+b;
else if(ch=='-')
result=a-b;
else if(ch=='*')
result=a*b;
else if(ch=='/')
result=a/b;
else
{
cout<<"\n"<<"Wrong operator!"<<"\n";
goto lb;
}
cout<<"\n"<<"The calculated result is : "<<"\n"<<result<<"\n";
lb:
getch();
return 0;
}
========================================================================
OUTPUT:
Enter two numbers: 9 9
Enter the operator(+,-,*,/): *
The calculated result is : 81
========================================================================
No comments:
Post a Comment