Code.GeekInterview.com
 
Code Samples Perl
 

Currency Converter


Code ResourceAuthor: srinivasaraobora  

Difficulty Level: Intermediate

Published: 25th Apr 2009   Read: 5802 times  

Filed in: Perl
Add Comment


 

 

Sponsored Links


 

 

This code shows Currency converter Please enter the Yen to pound exchange

 


Sample Code
  1. #!/usr/bin/perl
  2.  
  3. #Ex2_1.plx
  4. use warnings;
  5. use strict;
  6.  
  7. print "Currency converternnPlease enter the Yen to pound exchange rate: ";
  8.  
  9. my $yen = <STDIN>;
  10.  
  11. #Prompt user to input amounts, and do the conversions:
  12. print "Now please enter your first amount: ";
  13. my $first = <STDIN>;
  14. my $a = ($first/$yen);
  15. print "Enter your second amount: ";
  16. my $second = <STDIN>;
  17. my $b = ($second/$yen);
  18. print "Enter your third amount: ";
  19. my $third = <STDIN>;
  20. my $c = ($third/$yen);
  21.  
  22. #turn the results into values with no more than 2 decimal places, and rounded #to 2 places too.
  23.  
  24. my $mod1 = (int (100*$a)/100);
  25. my $mod2 = (int (100*$b)/100);
  26. my $mod3 = (int (100*$c)/100);
  27.  
  28. #Get rid of trailing newline character:
  29. chomp ($first, $second, $third);
  30.  
  31. #print out answers with two decimal place accuracy:
  32. printf ("$first Yen is %.2f poundsn", $mod1);
  33. printf ("$second Yen is %.2f poundsn", $mod2);
  34. printf ("$third Yen is %.2f poundsn", $mod3);
Copyright GeekInterview.com


Next Article: PassCripting - Crypt Perl Password


 

Latest Code Samples

 

Popular Code Samples

 

Related Code Samples

 

Post Your Comment:

Members Please Login
Your Name:*
e-mail ID:(required for notification)*
Image Verification: 
 
 Subscribe    



Popular Coders

# Coder NameHits
1. srinivasaraobora29511

Active Coders

# Coder NameCodes
1. srinivasaraobora5

Refined Tags