I have to write a program that will evaluate simple binary numerical expressions using operand1, operator, operand2. There are 8 operators the user can use: +, -, *, /, div: integer division, mod: remainder operation, ^:power, and %:percent. The operands & the result have to be double. I am new to C++ and I keep getting error C2059: syntax error : ')' on line 16 of my program. I will take any suggestions.
Here's what I have:
#include <iostream>
usingnamespace std;
int main()
{
double Op1, Op2, result;
char Operator;
cout << "This program is used to calculate numerical expressions." << endl;
cout << "If you wish to continue, please enter a number, followed by an operator, and another number " << endl;
cin >> Op1 >> Operator >> Op2;
if (Operator == +) //summation
result = Op1+Op2
elseif (Operator == -) //subtraction
result = Op1-Op2
elseif (Operator == *) //multiplication
result = Op1*Op2
elseif (Operator == /) //division
result = Op1/Op2
elseif (Operator == div) //integer division
result = Op
elseif (Operator == mod) //modulus
result = fmod(Op1,Op2)
elseif (Operator == ^) //power
result = Op1^Op2
else (Operator == %) //percent
result = Op1%Op2
system("pause>nul");
return 0;
Operator is a char variable, so you have to check its value in this way: if ( Operator == '+' ) , single quotations marks around the character. And please use code tags (select the piece of code and click the <> button).