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";
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
|
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
|
|