perl practice

perl practice

人民币/美金根据汇率进行转换

print<<EOF;

This is a currency convert program;
    
please input the exchange rate and select the local currency;
    
EOF

print "please input the exchange rate between dollar and RMB","\n";

chomp(my $exchange_rate = <STDIN>);

print "the exchange rate you set is $exchange_rate","\n";

print "please select RMB or dollar as your local currency","\n";

chomp(my $currency = <STDIN>);

print "you set $currency as you local currency","\n";

if($currency eq "RMB") {
    
    print "please input the amount of your local currency","\n";
    
    chomp(my $amount = <STDIN>);
    
    print "the amount of RMB is $amount","\n";
    
    print "RMB convert to dollar,the amount is ",$amount/$exchange_rate;
    
} elsif($currency eq "dollar") {
    
    print "please input the amount of your local currency","\n";
    
    chomp(my $amount = <STDIN>);
    
    print "the amount of dollar is $amount","\n";
    
    print "dollar convert to RMB,the amount is ",$amount*$exchange_rate;
    
} else {
    
    print "the currency you set is wrong","\n";
    exit;
    
}

ATM


my $info = <<"EOF";

The amount must can divide by 5;

Your account should be great than your amount;

Every time need pay 0.5 dollar for Handling fee;

original link: https://www.codechef.com/problems/HS08TEST

EOF

print $info;

print "Please input the amount you wanna get","\n";

chomp(my $amount = <STDIN>);

print "the amount you input is $amount\n";

print "Please input the account amount you have","\n";

chomp(my $account = <STDIN>);

print "the account amount you have is $account\n";

if($amount%5 != 0) {
	
	print "The amount you input cant divide by 5\n";
	
} elsif($amount > $account) {
	
	print "you account is not enough for you amount\n";	
		
} else {

	print "Please wait a moment,tou will get $amount dollar\n";
	
	print "Now your account have ",$account-$amount-0.5," dollar\n";
	
}

posted @ 2021-06-25 07:05  MOVIT  阅读(39)  评论(0编辑  收藏  举报