To divide one number by another you could probably pass both numbers, say a and b, to the function with intention of doing a/b. Check if b is zero, because dividing by zero is undefined. Within the function you can declare two numbers, say c and d, with c being how many times you can substract b from a and still have a number zero or more and d being the remainder (eg, 10/3 = 3 with 1 remainder translates to a = 10, b = 3, c = 3, d = 1). This type of division is called integer math and is how C++ implements the / operator for type int. What you display or return is up to you. In C++ the return is just c and d is ignored, but you can display both within the function, return c only, whatever. Using the above variable names the main part of the function could look like:
c = 0
d = a
while b <= d
d = d - b
++c
display c and d
Lerner
Nearly a Posting Maven
2,382 posts since Jul 2005
Reputation Points: 739
Solved Threads: 396