If I was approaching this homework problem this is what I would do ...
Q1. CanDispense(amt)
- Can I divide amt by 50 and if so is there anything left?
- Can I divide the remainder by 20 and if so is there anything left?
- If I take the number of 50's plus the number of 20's does it equal amt?
So I'm going to need Integer Division (/) and possibly the remainder (
modulus[
^])
Q2. Dispense50s(amt)
- Can I divide amt by 50 and what is the result?
So I'm going to need Integer Division (/). And nothing else really - I'll either get 0 (zero) or the number of 50-bills I need.
Hang on a minute, that Dispense50s function could be
called from the CanDispense function. Hm ... I could do a Dispense20s function as well and use that in the CanDispense function too.
So now my CanDispense function is going to look like
1. How many 50's do I need
2. How Many 20's do I need
3. If I add up all the bills I have does it equal the original amount?
Member 12343138102 said:
So assuming in Q1, if I got 5 bills of 50 and 2 bills of 20, then in Q2, it will means that the answer is 5?
No. See the quote from Kornfield Eliyahu Peter. Your homework as it stands does not ask you to get the number of 50-bills in Q1. However if you look at my train-of-thought you can use that information the other way around ... so you were actually on the right track.
Member 12343138102 said:
Also was wondering in cases like this, is it alright to print out any output message that state how many bills of 20s and 50s you will be getting based on the above questions?
That is entirely up to you, and possibly your tutor. Certainly it's a good idea when debugging but you might not want it in your final program. It's likely to be the next stage in the assignment anyway :)
Give it a go, and come back if you get stuck on the actual results