Question:
How do you get the remainder in C++?
Anne
2010-01-23 19:09:47 UTC
I wrote the problem as: quotient = num - 19*int(num/19)
I only get the quotient though but I need to get the remainder as well. I know you need to put this symbol % in the problem but I don't know where it'll fit without giving you errors. Please help.

Also the tutorials online were of little or no help when it came to getting a remainder.
Four answers:
anonymous
2010-01-23 19:19:31 UTC
% will give you the remainder.



remainder = num % 19;
Paul
2010-01-23 19:14:53 UTC
In your equation, it looks like you're multiplying by 19, then dividing by 19, which could be canceled out.



Anyways, the remainder you're looking for can be found using the modulus (%) operator. You would put that where you need it instead of the division operator to get the remainder.
Chris C
2010-01-23 19:58:51 UTC
Try the modf() function: http://www.cplusplus.com/reference/clibrary/cmath/modf/
orly
2010-01-23 19:12:51 UTC
http://www.cprogramming.com/tutorial/modulus.html


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Continue reading on narkive:
Loading...