[try Beta version]
Not logged in

 
solved tnx

Sep 12, 2015 at 11:37am
solved ty all
Last edited on Sep 12, 2015 at 3:55pm
Sep 12, 2015 at 11:45am
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.
Sep 12, 2015 at 11:48am
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.
Sep 12, 2015 at 12:22pm
solved tnxxxxx
Last edited on Sep 12, 2015 at 3:54pm
Sep 12, 2015 at 12:24pm
int quotient : 0
It is correct, 10 / 57 = 0;

int remainder : 0
You made a mistake somwhere in your code. 10 % 57 = 10
Sep 12, 2015 at 12:31pm
solved ty
Last edited on Sep 12, 2015 at 3:54pm
Sep 12, 2015 at 1:17pm
solved tnx
Last edited on Sep 12, 2015 at 3:54pm
Sep 12, 2015 at 1:21pm
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.
Sep 12, 2015 at 1:34pm
Example of finding both quotent and remainder at the same time: http://coliru.stacked-crooked.com/a/25b0cd1ceb0aa763
Sep 12, 2015 at 1:48pm
solved
Last edited on Sep 12, 2015 at 3:54pm
Sep 12, 2015 at 1:51pm
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.