Computer Science Canada

Money Code

Author:  spiderman [ Mon Dec 12, 2005 6:41 pm ]
Post subject:  Money Code

Does anyone know how to input a dollar ammount representing the fewest number of bills and coins? An example would be $25.53 dollars which is a twentie dollar bill, a five dollar bill, two quarters and three pennies. How would u do that on turing so that the user enters whatever dollar amount they want and answers it in fewest number of bills and coins. I know u have to use mod and div operators but i dont know how to write this code down?

Author:  Cervantes [ Mon Dec 12, 2005 7:32 pm ]
Post subject: 

Using your example, the largest bill/coin that can exist that is less than your value is the $20 bill. You start with this. Then you check if adding an extra $20 bill would put you over the limit. It does, since $40 > $25.53.

You then go to the next smallest bill. $10. Adding that to your tally gives you $30, which is still too big.

Go to the $5 bills. Add one, you get $25. Yay! Add another, you get $30, that's too much.

So now we've got a $20 and a $5 on the table.

Try a toonie. Nope, that's too much. So is a loonie. A quarter will fit. Two quarters will not. So we have a $20, a $5, and a $0.25.

A dime is too much. So is a nickel. Add a pennie. Add another. Add another. We've got it!


This would be made easier if you knew about arrays and recursion. Check [Turing Tutorials]. There are also links in the Turing Walkthrough.

Author:  spiderman [ Mon Dec 12, 2005 8:45 pm ]
Post subject: 

That doesn't really help me i already knew that i just doent know how to write it out in code!!!!!!!!

Author:  Cervantes [ Mon Dec 12, 2005 9:36 pm ]
Post subject: 

Ah. Well, in that case, know that we don't do homework for people, for obvious reasons. Show us the code you've got currently, and we'll help you out with it. Or post your algorithm.


: