solved tnx

solved ty all
Last edited on
Only loops, or are if statements allowed?
Not that I'll hand out code on homework, but I can say that both division and remainder can easily be done at once with a loop and an if statement.

Just think about division actually represents, taking a total and dishing it out evenly.

Hint, you can take user entered variables as the number of times to run a loop.
You can get quotent by doing multimplication backward — substract divisor from dividend, keeping a running count, until youcannot substract without going into negatives:

570 - 57 - 57 - ... - 57 = 0. As 57 repeats 10 times, 570/57 is 10. Remainder would be found in similar way:

44 - 6 - 6 - 6 - 6 - 6 - 6 - 6 = 2. As 6 repeats 7 times and in the end result is 2 then 44/6 is 7 and 44%6 is 2.
solved tnxxxxx
Last edited on
int quotient : 0
It is correct, 10 / 57 = 0;

int remainder : 0
You made a mistake somwhere in your code. 10 % 57 = 10
solved ty
Last edited on
solved tnx
Last edited on
I'd use a while loop (not a do while for this). Simple algorithm would go like this.
Check if the right hand number is negative.
If it is, store this and make it positive.
Declare a loop counter which starts at 0
Declare a total which starts at 0
while the loop counter is less than the second user inputted number, add the first user inputted number to the total
If the right hand number was negative, take the total away from 0.
Example of finding both quotent and remainder at the same time: http://coliru.stacked-crooked.com/a/25b0cd1ceb0aa763
solved
Last edited on
im now left on how to get the product..
It is most simpe thing. To multiply a × n, you need to add a n times.
Something like
1
2
3
4
mul = 0
loop n times
    add a to sum
end loop
Topic archived. No new replies allowed.