Code Golf: Banknote calculator
Posted
by paxdiablo
on Stack Overflow
See other posts from Stack Overflow
or by paxdiablo
Published on 2009-09-30T03:57:25Z
Indexed on
2010/03/31
16:13 UTC
Read the original article
Hit count: 383
This question was posted by a C beginner and it was an exercise to calculate, given a dollar value input by the user, the minimum number of bills (or banknotes, depending on your locale) needed to reach that dollar value.
So, if the user entered 93, the output would be:
$20 bills = 4
$10 bills = 1
$5 bills = 0
$1 bills = 3
Finally succumbing to the phenomenon (it's a slow day here), I thought this would be ripe for a game of Code Golf.
For fairness, the input prompt needs to be (note the "_" at the end is a space):
Enter a dollar amount:_
I think I've covered all the bases: no identical question, community wiki. I won't be offended if it gets shut down though - of course, I'll never be able to complain about these types of questions again, for fear of being labelled a hypocrite :-)
Okay, let's see what you can come up with. Here's a sample run:
Enter a dollar amount: 127
$20 bills = 6
$10 bills = 0
$5 bills = 1
$1 bills = 2
© Stack Overflow or respective owner