how to get the remainder of two input number?

user input 2 numbers, the program need print out the remainder of these two numbers. can not use mod functions.

my method is use a simple loop that persorms the subtraction (big number - small number), but i found if user input negative number, this program can not print out correct answer

anyone can help me?
ericylrAsked:
Who is Participating?
 
petiexCommented:
Correction, not until, but while:

That is, first assign your return value to the absolute value of the first argument, then, WHILE the difference between the return value and the second argument is greater than the absolute value of the first argument, subtract the absolute value of the second argument from the return value.

It would be much simpler to post the code, but it would be wrong for me to just do your homework for you.
0
 
CEHJCommented:
Please post what you'vre done so far
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
>but i found if user input negative number, this program can not print out correct answer

so you simply have to check before your loop if the 2 values are positive numbers.
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
petiexCommented:
The mod function always returns a value that is the same sign as the first number, regardless of the sign of the second number.

So, first determine the sign of the first argument (boolean isNeg = first<0;).

Then, subtract the absolute value of the second argument from the absolute value of the first argument until you get a value less than the first number.

Finally, if the first argument was negative, subtract the return value from zero.
0
 
petiexCommented:
Also, if the absolute value of the first argument is less than the absolute value of the second argument, then just return the first argument.
0
 
CEHJCommented:
petiex: please see the site guidelines about homework
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.