Roresishms

A Virtual World of Live Pictures.

Open a text editor, for example Notepad, and enter the following lines of code:

#!/usr/bin/perl-w

print “Monthly deposit: “; # input request

$deposit=; # get input from the keyboard

chomp $deposit; # remove the newline character from the end of the variable

print “Interest rate (3, 4, 5.5, etc.): “; # input request

$interest=; # get input from the keyboard

chomp $interest; # remove the newline character from the end of the variable

# Change the interest to 3, 4, 5, etc. to .03, .04, .05, etc.

$interest=$interest*.01;

# Change the interest to a monthly multiplier

$interest=$interest/12;

print “No of months: “; # input request

$nMonths=; # get input from the keyboard

chomp $nMonths; # remove the newline character from the end of the variable

# The interest calculation

$total=$deposit * (((1 + $interest) ** $nMonths) -1 ) / $interest;

print “After $nMonths months will have a total amount of $total”;

(Note: The spaces on either side of STDIN are for display purposes only in this article. In your script, you can omit them.)

Save the script as interest.pl. Take note of the directory/folder where you have saved it.

Running the script

You must run the script from a command line prompt, so open an MS-DOS terminal/prompt window. Change to the directory/folder where the interest.pl the file is found and type the following command:

interest perl.pl

When prompted, enter the monthly deposit, the interest rate, and the number of months the money is deposited.

message error

If the script did not work, you probably received one of the following error messages:

  • ‘Bad command or file name’ or ‘Command not found’. This means that Perl has not been added to the PATH variable. Consult your operating system’s help/documentation for information on how to fix this problem.
  • ‘Cannot open perl script interest.pl: a file or directory does not exist’. This probably means that you are not in the folder/directory where you saved the script, in which case you should change to the correct location.
  • If you get a syntax error, it probably means that you have mistyped the contents of the file. Open the file and correct any errors.

Leave a Reply

Your email address will not be published. Required fields are marked *