Order of Precedence

Posted on 2005-04-11
Last Modified: 2012-05-05
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!!!
Question by:Calv1n
    LVL 30

    Expert Comment

    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 :-)
    LVL 55

    Expert Comment

    by:Jaime Olivares
    modulus has the same precedence as division
    LVL 5

    Accepted Solution

    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?
    LVL 16

    Expert Comment

    >26-14 % 3 + 1
    The answer is 25, not 24.
    LVL 16

    Expert Comment

    What was the guy asking and what he really wanted to ask...

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
    In Easy String Encryption Using CryptoAPI in C++ ( I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now