• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 223
  • Last Modified:

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!!!
1 Solution
Hi Calv1n,
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 :-)
Jaime OlivaresCommented:
modulus has the same precedence as division
How do I use the "%" modulus operator on the calculator?
do you mean electronic calculator?
if you want to do 14 % 3 in a calculator.
you can do like this 14 divide by 3 you will get answer like 4.6666667 (let's say a.bbbbbbb)
then you minus whatever is a then you multiply back 3 then you can get the modulus value which is 2.

Is this what you want?
>26-14 % 3 + 1
The answer is 25, not 24.
What was the guy asking and what he really wanted to ask...

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now