Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

C# C# Basics (Retired) Perform Order of Operations

Sreeny G
Sreeny G
2,642 Points

is 8*7+8%5+6/2 same as (8*7)+(8%5)+(6/2)?

I end up with 60 for the below expression. Please advise where I'm doing it wrong.

Expression: 8*7+8%5+6/2

My thoughts: we have *, %, /, + so with order of precedence (left to right), I do this: 56 + 1 + 3 = 60.

2 Answers

Steven Parker
Steven Parker
231,210 Points

It looks like you understand the operator precedence correctly .. that's most of it!

But 8 % 5 does not equal 1.

The "%" symbol is the modulus or remainder operator. It gives you what would be left over after a divide. So, for example, 12 % 10 would be 2.

Sreeny G
Sreeny G
2,642 Points

Thanks Steven! That's so silly of me to assume it to be dividend.