Hello,
Now there is this strange exercise:
Write a program that takes an operation followed by two operands and outputs the result. For example:
+ 100 3.14
*4.5
Read the operation into a a string called operation and use an if-statement to figure out which operation the user wants, for example, if(operation=="+"). Read the operands into variables of type double. Implement this for operands called +, -, *, /, plus, minus, mul, and div with their obvious meanings.
Now I`m not sure if I fully understand the question, but I will do my best.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
#include<iostream>
#include<string>
int main()
{
string operation;
double a=0.0
double b=0.0
cout<< "Enter two numbers and select operation (+, -, * or /)";
cin>>a>>b;
cin>> + >> - >> * >> /;
if (operation == "+") { cout<< " << a + b << "; }
else if (operation == "-") { cout<< " << a - b << "; }
else if (operation == "*") { cout<< " << a * b << "; }
else if (operation == "/") { cout<< " << a / b << "; }
}
|
When trying to compile though, getting error message.