#include <iostream>
void calculate(float a, char op, float b);
int main()
void calculate(float a, char op, float b)
{
switch(op) {
case '+':
std::cout << "\nAddition of two numbers is " << (a + b);
break;
case '-':
std::cout << "\nSubtraction of two numbers is " << (a - b);
break;
case '*':
std::cout << "\nMultiplication of two numbers is= "<< (a * b);
break;
case '/':
std::cout << "\nDivision of two numbers is= "<< (a / b);
break;
default:
std::cerr << "\nUnkown operator!";
}
}
{
float a, b; // These are useless: sum, sub, mul, divide, mod
char op; //operands and operators are entered by the user
std::cout.exceptions(std::cout.failbit);
std::cin.exceptions(std::cin.badbit);
std::cerr.exceptions(std::cerr.failbit);
std::cout << "Enter any two operands with operator=";
if (std::cin >> a >> op >> b)
calculate(a, op, b);
return 0;
}
Comments
Leave a comment