Question

In: Computer Science

Perl Programming Write a Perl script that computes compound interest balance, A, based on input from...

Perl Programming

Write a Perl script that computes compound interest balance, A, based on input from user for P, n, r and t.

Solutions

Expert Solution

Exercise: Interest Calculator


For this exercise, you're going to perform a compound interest calculation. This program will calculate the interest on a savings account, given some information about interest rates, deposits, and time. The formula you're going to use is as shown here:

Using your text editor, type the program from Listing 2.2 and save it as Interest. Do not type in the line numbers. Make the program executable according to the instructions you learned in Hour 1.

When you're done, try running the program by typing the following at a command line:

Listing 2.2 The Interest Program
1:  #!/usr/bin/perl -w
2:
3:  print "Monthly deposit amount? ";
4:  $pmt=<STDIN>;
5:  chomp $pmt;
6:
7:  print "Annual Interest rate? (ex. 7% is .07) ";
8:  $interest=<STDIN>;
9:  chomp $interest;
10:
11: print "Number of months to deposit? ";
12: $mons=<STDIN>;
13: chomp $mons;
14:
15: # Formula requires a monthly interest
16: $interest/=12;
17:
18: $total=$pmt * ( ( ( 1 + $interest) ** $mons ) -1 )/ $interest;
19:
20: print "After $mons months, at $interest monthly you\n";
21: print "will have $total.\n";
perl Interest
Listing 2.3 shows a sample of the Interest program's output.

Line 1: This line contains the path to the interpreter (you can change it so that it's appropriate to your system) and the -w switch. Always have warnings enabled!

Line 3: The user is prompted for an amount.

Line 4: $pmt is read from the standard input device (the keyboard).

Line 5: The newline character is removed from the end of $pmt.

Lines 7–9: $interest is read in from the keyboard, and the newline is removed.

Lines 11–13: $mons is read in from the keyboard, and the newline is removed.

Listing 2.3 Output from the Interest Program
1: Monthly deposit amount? 180
2: Annual Interest rate? (ex. 6% is .06) .06
3: Number of months to deposit? 120
4: After 120 months, at 0.005 monthly you
5: will have 29498.2824251624.
Line 16: $interest is divided by 12 and stored back in $interest.

Line 18: The interest calculation is performed, and the result is stored in $total.

Lines 20–21: The results are printed.

Related Solutions

Perl Programming Please write a simple to understand Perl script that computes compound interest, based on...
Perl Programming Please write a simple to understand Perl script that computes compound interest, based on input from user for P, n, r and t.
Perl is a programming language that can be used on Linux. Write a Perl shell script...
Perl is a programming language that can be used on Linux. Write a Perl shell script named phone.pl that prompts the user to enter first or last or any portion of person’s name, so that can be found the appropriate entry in the phone directory file called “phones”. If the user tries to enter name as the argument on the command line, he/she will get a warning message “You need to provide name when prompted by this script!” If the...
SHOW SCREEN SHOTS OF THE INPUT AND OUTPUT AS WELL AS THE RESULTS PROGRAMMING IN PERL...
SHOW SCREEN SHOTS OF THE INPUT AND OUTPUT AS WELL AS THE RESULTS PROGRAMMING IN PERL Task 2: Variables 2.1 Scalar Variables A scalar is a single unit of data. That data might be an integer number, floating point, a character, a string, a paragraph, or an entire web page. Simply saying it could be anything, but only a single thing. #!/usr/bin/perl $age = 35; # An integer assignment $name = "Gary Mann"; # A string $salary = 5445.50; #...
Assisted Instruction: Has to be in PERL SCRIPTING LANGUAGE with NO SUBROUTINES Programming Exercise: Write a...
Assisted Instruction: Has to be in PERL SCRIPTING LANGUAGE with NO SUBROUTINES Programming Exercise: Write a program in PERL with NO SUBROUTINES to allow the user to pick a type of arithmetic problem to study. An option of 1 means addition problems only, 2 means subtraction problems only, 3 means multiplication problems only, 4 means division problems only and 5 means random mixture of all these types. (Computer- Assisted Instruction) The use of computers in education is referred to as...
Write an Assembly code to input two integer numbers from keyboard, computes the division of two...
Write an Assembly code to input two integer numbers from keyboard, computes the division of two numbers WITHOUT using division operator and print out the reminder and quotient to the screen. Note: program using “division operator” will earn no credit for this task. You are ALLOWED to use the “print” and “read” macro
Write a Matlab script that computes the element level stiffness matrix and force vector for linear...
Write a Matlab script that computes the element level stiffness matrix and force vector for linear elasticity.
You have to write a program that computes the area of a triangle. Input consists of...
You have to write a program that computes the area of a triangle. Input consists of the three points that represent the vertices of the triangle. Points are represented as Cartesian units i.e. X,Y coordinates as in (3,5). Output must be the three points, the three distances between vertices, and the area of the triangle formed by these points. The program must read the coordinates of each point, compute the distances between each pair of them and print these values....
Write a Java method that takes an input string and computes the income minus the expenses....
Write a Java method that takes an input string and computes the income minus the expenses. The income components are indicated by numbers; while the expenses from your spending are numbers starting with a minus sign '-'. The input string may contain lowercase and uppercase letters, as well as other characters. Note that Character.isDigit(char) tests if a char is one of the chars '0', '1', ..., '9'. Also recall that Integer.parseInt(string) converts a string to an int. Test cases :...
Write a Python script that takes an input image and output's the name of the dominant...
Write a Python script that takes an input image and output's the name of the dominant color in that image(i.e. red, green, blue).  
⦁   Write a Bash script that prompts for user input and reads a string of text...
⦁   Write a Bash script that prompts for user input and reads a string of text from the user. If the user enters a no null (no empty) string, the script should prompt the user to re-enter again the string; otherwise should display the string entered “. ⦁   Given an array of the following four integers (3, 5, 13, 14); write a Bash script to display the second and all elements in the array.    ⦁   Write a short Bas...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT