HELP in a logical issue

S

sonhadorPR

How can I tell a computer, in C++, to give me the reminder on a
division problem?
If (Quotient)(Divisor) + Reminder = Dividend
How do I get the reminder by itself?
How do I tell C++ that I want the reminder.
If I write
quot = num2/num1; It won't give me the reminder.
Thank you for your help.
Roberto Millan, frustrated programmer :/
 
T

Thomas Tutone

How can I tell a computer, in C++, to give me the reminder on a
division problem?
If (Quotient)(Divisor) + Reminder = Dividend
How do I get the reminder by itself?
How do I tell C++ that I want the reminder.
If I write
quot = num2/num1; It won't give me the reminder.
Thank you for your help.
Roberto Millan, frustrated programmer :/

In C++ (and in C), the modulo operator is %. It gives the "remainder"
of an integral division. For example:

int i = 7 % 3; // i is now equal to 1, which is the remainder of 7
divided by 3.

Best regards,

Tom
 
R

red floyd

How can I tell a computer, in C++, to give me the reminder on a
division problem?
If (Quotient)(Divisor) + Reminder = Dividend
How do I get the reminder by itself?
How do I tell C++ that I want the reminder.
If I write
quot = num2/num1; It won't give me the reminder.
Thank you for your help.
Roberto Millan, frustrated programmer :/

What book are you reading that doesn't mention the % (modulo) operator?
 
J

Jerry Coffin

How can I tell a computer, in C++, to give me the reminder on a
division problem?

C++ provides the modulus operator (%), which will generally do the job.
If you have to deal with negative numbers, you may need to do a little
extra work to get exactly what you want though.
 
F

Frederick Gotham

posted:
How can I tell a computer, in C++, to give me the reminder on a
division problem?
If (Quotient)(Divisor) + Reminder = Dividend
How do I get the reminder by itself?
How do I tell C++ that I want the reminder.
If I write
quot = num2/num1; It won't give me the reminder.
Thank you for your help.
Roberto Millan, frustrated programmer :/


If you want both, then consider "div":

http://www.dinkumware.com/manuals/?
manual=compleat&Search=div&page=stdlib.html#div
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,607
Members
45,241
Latest member
Lisa1997

Latest Threads

Top