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 Math

christopher slater
christopher slater
3,038 Points

modulus problem!!!!

i did the example and got the correct answer but when i do the quiz question it returns the wrong answer but i am positive the answer is correct. math work below

question 8*7+8%5+6/2 56+8%5+6/2 //8*7=56 1+8+6/2 //56%5= 56-(56/5)*5))=1 .5+8+6 // 1/2=.5 =14.5 8+6+.5=14.5

can some one please tell me what i am doing wrong ?! it would be much appreciate !!

2 Answers

Prateek Jain
PLUS
Prateek Jain
Courses Plus Student 1,797 Points

Hey,

Let's go about doing it step by step:

Question: 8*7+8%5+6/2 Step One: 8*7 = 56

New Question: 56+8%5+6/2 Step Two: (As per Maths Rule): 8%5 = 3

New Question: 56 + 3 + 6 / 2 Step Three: 6 / 2 = 3

New Question: 56 + 3 + 3 Therefore Answer is 62.

If you are not aware of the BODMAS Rule, please learn that first so you can solve this problem with more clarity.

Where you might be going wrong is that you are taking the first number in the complete equation and applying it to the next operator.

If you have say 10 + 11 * 12 % 5 - The first step would be to complete the Multiplications and Divisions from left to right. Therefore we have to solve 11 * 12 first and not 10 * 12.

After solving that we get a new question 10 + 132 % 5 (11 * 12 = 132). Here, we need to solve 132 % 5 first and not 10 % 5.

After solving that we get 10 + 2 (132 % 5 = 2).

Final answer being 12.

Hope this helps.

christopher slater
christopher slater
3,038 Points

thank you so much i see what i was doing wrong i was taking the remainder of the multiplication and applying the modulus and division instead of using the value given awesome i really appreciate the help!