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
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: