Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

basic C

Name: Anonymous 2010-11-24 12:17

can you help create a program that will accept an amount and output its denomination.

example

amount: 5670.45

1000: 5
500: 6
200: 0
100: 6
50: 1
20: 1
10: 0
.25: 1
.05: 3

Name: Pwerlwrl 6 2010-11-24 19:11

Not really related, but what the hell ....


use v6;
my $amount = 5670.45;
my %change;
for <1000 500 100 50 10 5 1 0.50 0.25 0.01> -> $d {
  while $amount >= $d {
    %change{$d}++;
    $amount -= $d
  }
};
%change.perl.say;


Output:

{"1000" => 5, "500" => 1, "100" => 1, "50" => 1, "10" => 2, "0.25" => 1, "0.01" => 19}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List