. Write a program that simulates a simple calculator. It reads two integers and a character. If the character is +, then the sum of the two numbers is printed, if the character is –, then the difference of the two numbers is printed, if the character is *, then multiplication of the two numbers is printed; if the character is /, then the quotient is printed; if the character is %, then the remainder is printed.
#include <iostream>
int main()
{
char action = '.';
double a = 0, b = 0;
std::cout<<"Please enter two integers: ";
std::cin>>a>>b;
std::cout<<"Please enter an action to these integers (+, -, *, /, %): ";
std::cin>>action;
switch(action)
{
case '+':
std::cout<<a+b<<std::endl;
break;
case '-':
std::cout<<a-b<<std::endl;
break;
case'*':
std::cout<<a*b<<std::endl;
break;
case '/':
std::cout<<a/b<<std::endl;
break;
case '%':
std::cout<<(int)a%(int)b<<std::endl;
break;
}
return 0;
}
Comments
Leave a comment