Created
December 30, 2013 02:02
-
-
Save tobyink/8176950 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
print "Amount (in pounds)?\n"; | |
chomp(my $amount = <>); | |
$amount = sprintf('%.1f', $amount * 100); | |
my %coinage = ( | |
1 => 'pennies', | |
2 => 'tuppennies', | |
5 => 'five pence pieces', | |
10 => 'ten pence pieces', | |
20 => 'twenty pence pieces', | |
50 => 'fifty pence pieces', | |
100 => 'pound coins', | |
200 => 'two pound coins', | |
); | |
my $remainder = $amount; | |
for my $value (sort { $b <=> $a } keys %coinage) { | |
my $quantity = int($remainder / $value); | |
print "$quantity $coinage{$value}\n" if $quantity; | |
$remainder %= $value; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment