Program trouble

closed account (Ebf21hU5)
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:


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
26
27
28
29
30
31
32
33
34
35
36
#include <iostream>


using namespace 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
	else if (Operator == -)		//subtraction
		result = Op1-Op2
	else if (Operator == *)		//multiplication
		result = Op1*Op2
	else if (Operator == /)		//division
		result = Op1/Op2
	else if (Operator == div)	//integer division
		result = Op
	else if (Operator == mod)	//modulus
		result = fmod(Op1,Op2)
	else if (Operator == ^)		//power
		result = Op1^Op2
	else (Operator == %)		//percent
		result = Op1%Op2
		
	

	system("pause>nul");
	return 0;
Last edited on
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).
closed account (Ebf21hU5)
Sorry I've only used this site once so I didn't know how to code tag. Thanks for your help.
Topic archived. No new replies allowed.