Notes Dispenser pointers needed

Feb 20, 2016 at 6:50pm
Hi all, I have just started out in C++ am trying to write up a cash dispenser code upon entered amount(assuming it as whole numbers - 100, 220 etc..) and to list out the least number of bills, butthe machine only dispense 20 and 50 bills.

So far I am able to write my code by first dividing the entered amount by 50, then by 20 (amount reduction of the 50s)
However while doing so, I realize that should I entered in an amount, say 480, I will be getting 9 bills of 50 and a bill of 20 as my output (a missing 10 amount here), in which it should be 8 bills of 50 and 4 bills of 20.

I am somewhat lost and was wondering if anyone give me any pointers on how I should approach this?
Last edited on Feb 21, 2016 at 4:47am
Feb 20, 2016 at 7:19pm
You need to do the 20's first


1
2
3
4
    while((dollar_amount % 50) != 0 )
    {
        //remove 20
    }
Feb 21, 2016 at 4:46am
Hi, can you explain why remove 20 is needed? I don't really understand here...
Feb 23, 2016 at 11:09am
anyone can help?
Feb 23, 2016 at 11:23am
One solution could be adding 50 (and decreasing the amount) to the remain untill it is divisible by 20. I.e. a second loop.
Feb 23, 2016 at 11:40am
The (better) idea of Yanson was to subtract 20 until the remain is divisible by 50. Just one loop would be required.
Feb 23, 2016 at 3:47pm
Pardon me if I sounded stupid but will that be a while loop? So far I have try covering topics like if else, for, while loops etc on my own and so am not exactly sure when to use which depending on scenario.

The coding I have been writing uses on if else and unfortunately I believe I am brute forcing through which is not ideal at all
Topic archived. No new replies allowed.