C++ program for some arithmetic calculation
In this program, the only basic arithmetic calculation like addition, subtraction, multiplication, division are performed. In the default case the only simple message will be printed like you are not "Enter Valid Operator! ".
#include <iostream>
using namespace std;
int main()
{
char ch;
int a, b, result;
cout<<"Enter first and second value: ";
cin>>a;
cout<<endl;
cin>>b;
cout<<endl;
cout<<"\n Enter operator: ";
cin>>ch;
cout<<endl;
switch(ch)
{
case '+': result=a+b; cout<<"Sum: "<<result; break;
case '-': result=a-b; cout<<"Difference: "<<result; break;
case '*': result=a*b; cout<<"Product: "<<result; break;
case '/': result=a/b; cout<<"Quotient: "<<result; break;
default: cout<<"Enter Valid Operator!";
}
}
Program output is tested on www.jdoodle.com
Enter first and second value:
4
5
Enter operator: *
Enter operator: Product: 20
Thanks
Mukesh Rajput
Post A Comment:
0 comments: