Calv1n
asked on
Order of Precedence
Hello, I am in a C++ class and I am having an issue with trying to manually compute a expression within the guidelines of order of precedence. I am mainly having an issue with using the modulus operator on xp's calculator. How do I use the "%" modulus operator on the calculator?
Here is a couple of expressions that I am having problem with:
26-14 % 3 + 1
The answer is 24
3 + 16 / 7 % 2
The answer is 3.0
Thank you for your help!!!
Here is a couple of expressions that I am having problem with:
26-14 % 3 + 1
The answer is 24
3 + 16 / 7 % 2
The answer is 3.0
Thank you for your help!!!
modulus has the same precedence as division
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>26-14 % 3 + 1
The answer is 25, not 24.
The answer is 25, not 24.
What was the guy asking and what he really wanted to ask...
When ever there is a question of precedence, I recommend you use () to wrap around objects you want associated together. Most programmers don't keep the complete order of precedence memorized, and even if you did, any one maintaining your code would probably have trouble predicting the out come of your code.
You can try something like the following method:
= (26-14) % (3 + 1);
David Maisonave :-)
Cheers!