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!
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
I'm stuck on the maths for C# basics the question is 8 * (7+8) % 5 + 6/2
I thought you would do the parenthesis first leaving 15 between them, multiplied by 8 giving the value of 120, then taking 5 away you are left with 115, then dividing 6 by 2 is 3, adding 115 and 3 together gets 118 but it is wrong. I'm not sure how I'm messing up the order but any help would be appreciated
Jennifer NordellTreehouse Teacher
It's not subtracting by 5 .,.. it's getting the mod of 120 and 5. So it looks like this.
8 x (7 + 8) % 5 + 6 /2 =
8 x 15 % 5 + 6/2 =
120 % 5 + 6/2 =
0 + 6 / 2 = because 120 divided by 5 has a remainder of 0 aka it's evenly divisible by 5
0 + 3 =
Final answer: 3
Anjali Pasupathy28,883 Points
Here's a trick for the modulo!
7 + 8 is 15, which is divisible by 5. Because of this, multiplying that number by any other integer would still create a number divisible by 5. Because 8 * (7 + 8) is going to be divisible by 5, modding that number by 5 can only result in 0. That means that 8 * (7 + 8) % 5 is going to evaluate to 0, so you only need to worry about 6/2.
hey thanks you two are live savers ahaha