Hello Folks! Welcome to Our Blog.

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

#! / usr / bin / perl -w

print “Monthly deposit:”; # request for entry

$ deposit =; # get input from keyboard

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

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

$ interest =; # get input from keyboard

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

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

$ interest = $ interest * .01;

# Change the interest to a monthly multiplication

$ interest = $ interest / 12;

print “No. of months:”; # request for entry

$ nMonths =; # get input from keyboard

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

# The calculation of interest

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

print “After $ nMonths months you 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. Make a note of the directory / folder where you have saved it.

Running the script

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

perl interest.pl

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

Message error

If the script didn’t work, you probably received one of the following error messages:

  • ‘Wrong command or filename’ or ‘command not found’. This means that Perl has not been added to the PATH variable. See the help / documentation for your operating system 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 it is not in the folder / directory where you saved the script, in which case you have to change to the correct location.
  • If you get a syntax error, it probably means that you have misspelled the contents of the file. Open the file and correct the errors.

Leave a Reply

Inapurrear.com
Recent Comments