Hmm, do you just want it shorter and still produce the wrong total, or shorter and produce the correct total as well?
# Let's see how much money I would have if I just won the # lottery and found a 2 pound coin in the couch cushions... How many 5 pence pieces do you have? 0 How many 10 pence pieces do you have? 0 How many 20 pence pieces do you have? 0 How many 50 pence pieces do you have? 0 How many £1 coins do you have? 1000000000 How many £2 coins do you have? 1 How many £5 notes do you have? 0 How many £10 notes do you have? 0 How many £20 notes do you have? 0 How many £50 notes do you have? 0 You have £2. # Hmm, guess I won't spend my £2 on a lottery ticket then...
strict would have helped you out there... In any case...
#!/usr/bin/perl -w use strict; use warnings; use List::Util qw( sum ); printf( "You have £%.02f\n", sum ( ( map { ask( "$_ pence pieces", $_/100 ) } ( 5, 10, 20, 50 ) ), ( map { ask( "£$_ coins", $_ ) } ( 1, 2 ) ), ( map { ask( "£$_ notes", $_ ) } ( 5, 10, 20, 50 ) ), ) ); sub ask { print "How many $_[0] do you have? " ; <STDIN> * $_[1] }
In reply to Re: Can someone help me make this script more efficient
by jasonk
in thread Can someone help me make this script more efficient
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |