Studying C + +

Community Forums/General Help/Studying C + +

Yue(Posted 2011) [#1]

These days I've ridden a mechanical bull doing an online course in C + + level 1, if but for a person like me who do not finish primary school, have problems.

I show them my grades, I do not know if it is easy or that but it goes well.

 x = 3 + 4 * (8 * ( 4 – ( 9 + 3 ) / 6 ) );


In this case the compiled C + +, the variable takes the value of 67, but I support my answer and I can not understand how this is done.

Is to first solve () internally in your order out, but I get lost somewhere. Appreciate your help please.


big10p(Posted 2011) [#2]
It's because of precedence of operators. For example, * and / have a higher precedence than - and + so are executed first. The calculations don't simply go from left to right.


Yue(Posted 2011) [#3]
3 + 4 * (8 * ( 4 – ( 9 + 3 ) / 6 )
3  +4 * (8 *(4-12)/6)
3  +4 * (8 *(4-2))
3  +4 * (8 *2)
3 +4 *16
3 +64 = 67

If I pass the course c + + level 1 will be very happy, this is crazy.


Gabriel(Posted 2011) [#4]
Don't they teach BODMAS any more?

http://www.mathsisfun.com/operation-order-bodmas.html


Adam Novagen(Posted 2011) [#5]
BODMAS seems a bit of an obfuscated way... I learned that as PEMDAS. Parentheses (since, as I understand it, brackets are the { and } ones, or the [ and ] set), Exponents, Multiplication, Division, Addition, Subtraction. Memory hook for PEMDAS: "Please Excuse My Dear Aunt Sally." Seems silly, I know, but I remember PEMDAS, whereas BODMAS will probably have escaped my mind by tomorrow, if that. XD