#include <iostream>
double calculate(char op, double n1, double n2)
{
double var = 0.0 ; // initialise to zero
switch (op)
{
case'+':
var = n1 + n2;
break;
case'-':
var = n1 - n2;
break;
case'*':
var = n1 * n2;
break;
case'/':
var = n1 / n2;
break;
}
return var ; // return the result of the calculation
// note: we return zero if op is not one of +-*/
}
int main()
{
char op;
std::cout << "Enter x to end program\n"
<< "Enter the desired operand for the problem: " ;
std::cin >> op;
while(op != 'x')
{
double n1, n2 ;
std::cout << "Enter the first number: " ;
std::cin >> n1;
std::cout << "Enter the second number: " ;
std::cin >> n2;
// store the value returned by the function in result
constdouble result = calculate(op, n1, n2);
// and print out the result
std::cout << "The result is " << result << "\n\n" ;
// accept the value for the next operation
std::cout << "Enter the desired operand for the problem: " ;
std::cin >> op;
}
// there is an implicit return 0; at the end of main
}