-
if statement problemos
i'm trying to make a program that's menu-based that will perform addition, subtraction, multiplication, or division, but I can't get the if statement to work correctly, and i'm pretty sure i'm doing something horribly wrong. my failure of a code is attached. please help!
-
Code:
if(operation == '+' )
no1 + no2 == result;
else if(operation == '-')
no1 - no2 == result;
else if(operation == '*' )
no1 * no2 == result;
else if(operation == '/')
no1 / no2 == result;
That is where your problem is...
have you read assignment?
And also, enter valid data into variables before performing operations on it :P
-
Code:
no1 / no2 == result;
Backwards ... the variable holding the result always goes on the left of the assignment operator.
Wrong operator... == is a comparison ... = is an assignment.
-
-
And from what I know, the variable you are changing the value of should come first, like:
a=3+4,
not
3+4=a.