Write a simple calculator program in C++. It should input two numbers and a character. If the character is ‘+’, it should add two numbers and so on.
#include<iostream>
using namespace std;
int main(){
int a,b;
char c;
cout<<"Enter two numbers : "<<endl;
cout<<"a : ";
cin>>a;
cout<<"b : ";
cin>>b;
cout<<"Enter any character(+-*/%) : ";
cin>>c;
cout<<"Result : ";
switch(c){
case '+':cout<<a+b;break;
case '-':cout<<a-b;break;
case '*':cout<<a*b;break;
case '/':cout<<a/b;break;
case '%':cout<<a%b;break;
default :cout<<" ?";
}
return 0;
}
