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

Order of Operation are not working

I have run through the problem many times and even in the console, but the c# oder of ops gives me the wrong answer. This may be a bug or I am just completely wrong. Please Help!

4 Answers

james south
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
james south
Front End Web Development Techdegree Graduate 33,271 Points

the quiz does not have a bug. left to right (1) anything in parens (), then (2) multiplication, division and modulo are of the same priority, then (3) addition and subtraction are of the same priority. so do operation in parens, then look for mult, div and mod, do those left to right, then look for add and sub, do those left to right.

But my answer still comes to seven when i do what you say. What did you get

Seth Kroger
Seth Kroger
56,413 Points

There are 3 questions to the quiz, each with different answers. It would be helpful to know which question you're asking about. (FYI none of the quiz answers I see are 7),

I need help on #1, but I will still need help on others swell.

Seth Kroger
Seth Kroger
56,413 Points

The first one is 8 * 7 + 8 % 5 + 6 / 2 = ???. There are no parentheses so we start with *, /, and % left to right.

8 * 7 + 8 % 5 + 6 / 2 -> 56+ 8 % 5 + 6 / 2

56 + 8 % 5 + 6 / 2 -> 56 + 3 + 6 / 2

56 + 3 + 6 / 2 -> 56 + 3 + 3

Then the addition:

56 + 3 + 3 = 62

Thank you very much that helps a lot!