Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

Misha Karas
Misha Karas
5,636 Points

Modules #C basics

So i am doing the #C basic track and so far so good, but now i have a math question but i cand find a calculator what also does modules. So i want to know what the awnser is on this question and maybe also the question after this if they also contain modules. 8 * 7 + 8 % 5 + 6 / 2 = .........

2 Answers

Steven Parker
Steven Parker
215,372 Points

:point_right: You can also think of % as the remainder operator.

So for example, to calculate 8 % 5 on a "four-banger", you would first divide 8 by 5 — that gets you 1.6. Then, multiply just the fractional part (.6) by 5 — which gives you your answer (3).

But it's hard to imagine not having access to a calculator that would do this for you. If you use a windows computer, just bring up the on-screen calculator, be sure it is in scientific or programmer mode, and then use the MOD button. In this case, 8 MOD 5 will get you 3.

:information_source: The word for this operation is modulus. The term "modules" is also commonly used in programming, but has a different meaning.

Misha Karas
Misha Karas
5,636 Points

Thanks a lot! And thanks for the tip with modulus and modules :D