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

steeve Francois
PLUS
steeve Francois
Courses Plus Student 572 Points

Use what you learned about the order of math....... can some help with this? 8 * (7 + 8) %

Use what you learned about the order of math operations to solve this problem. You can use a calculator.......... can someone help with this cause I want to go forward until i get this

8 * (7 + 8) % 5 + 6 / 2 =

2 Answers

I like to use PEMDAS (Parenthesis, Exponents, Multiplication, Division, Addition, and Subtraction). We won't be using exponents so just ignore that for now. I use this to identify the order of operations. So first, we do what's in parenthesis.

8 * (7 + 8) % 5 + 6 / 2 ----> 8 * (15) % 5 + 6 / 2

Then, we do Multiplication, Division and the Modulus Operator (%). (just think of the M as Multiplication and Modulus).

Note: Even though there are multiple actions taking place at the same time in this step, we do it from left to right.

We first perform (8 * 15), then (120 % 5), and then (6 / 2). Notice how we skipped the + as weren't finished calculating the values of higher priority (Aka: Multiplication, Division, Modulus).

8 * (15) % 5 + 6 / 2 ---> 120 % 5 + 6 / 2 ---> 0 + 6 / 2 ---> 0 + 3

You see that with the modulus (%) operator, you only use the remaining value. Since 5 goes into 120 exactly 24 times, the remaining value is 0. But if you were to do 10 % 3 , for example, the remaining value would be 1, as 3 can only go into 10 three times, leaving a value of 1 unsatisfied.

With that, your final answer would be 3.

Thanks so much for this in depth comment Nickolans!

Cole Wilson
Cole Wilson
7,413 Points

8 * (7 + 8) % 5 + 6 / 2 = 8 * (15) % 5 + 6 / 2 = 120 % 5 + 6 / 2 = 0 + 6 / 2 = 3

So the answer is 3.