Wise Monks-
Am trying to write a currency conversion script that prompts successively until it obtains both "from" and "to" currencies that are within a hash. Not working, lol. Your advice is sought. Thanks much in advance.
#!/usr/bin/perl # convert3.pl use warnings; use strict; my ($value, $from, $to, $rate, $rates, %rates); %rates = ( pounds => 1, USD => 1.6, marks => 3.0, "french francs" => 10.0, yen => 174.8, "swiss francs" => 2.43, drachma => 492.3, euro => 1.5 ); print "Enter your starting currency: "; OUTER0: while (<STDIN>) { chomp; INNER0: for $from (%rates) { last OUTER0 if $from eq $_; } } print "Enter your target currency: "; OUTER1: while (<STDIN>) { chomp; INNER1: for $to (%rates) { last OUTER1 if $to eq $_; } } print "Enter your amount to convert: "; $value = <STDIN>; $rate = $rates{$to} / $rates{$from}; print "$value $from is ",$value*$rate," $to. \n";
In reply to a hash and 2 loops--not working by jhumphreys
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |