Simple Calculator in C++

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;
}
output of calculator program
output of calculator program

One Reply to “Simple Calculator in C++”

Leave a Reply

Your email address will not be published. Required fields are marked *