Share
Explore BrainMass

Explore BrainMass

Perl Program Update

Please apply the following formula below to the program so it works correctly!

The following formula is used to calculate the fixed monthly payment (P) required to fully amortize a loan of L dollars over a term of n months at a monthly interest rate of c. [If the quoted rate is 6%, for example, c is .06/12 or .005].

P = L[c(1 + c)n]/[(1 + c)n - 1]

I am currently getting the following errors

Number found where operator expected at calc.cgi line 38, near "#P = Lr(1+r/1200"
(Might be a runaway multi-line // string starting on line 15)
(Do you need to predeclare P?)
Unquoted string "n" may clash with future reserved word at mor_calc.cgi line 38.
Unquoted string "r" may clash with future reserved word at mor_calc.cgi line 38.
Unquoted string "n" may clash with future reserved word at mor_calc.cgi line 38.
Scalar found where operator expected at mor_calc.cgi line 39, near "$num_months"
(Missing semicolon on previous line?)
syntax error at mor_calc.cgi line 38, near "P = Lr(1+r/1200"
Missing right curly or square bracket at mor_calc.cgi line 61, at end of line
Execution of calc.cgi aborted due to compilation errors.

Thank you!

Attachments

Solution This solution is FREE courtesy of BrainMass!

Dear Student,

I have modified the script and named new_mor_cal.pl to follow the new formula given above. Please follow the following instructions on usage of this program.

usage: perl new_mor_calc.pl -L 20000 -y 15 -i 12

-L amount : Amount of loan.
-y years : Number of years
-i interest : Percent per year interest.
-h : prints this message.

For the above input data, the results when the perl is executed are,

perl new_mor_calc.pl -L 20000 -y 15 -i 12 > results.log

results.log
**************************************
Loan Amount = 20000
Number of Years = 15
Interest rate = 12
Monthly Interest rate C = ((12)/(12*100)) = 0.010000

**************************************
Your Mortgage is = 201.117318435754

I have attached the new_mor_cal.pl and results.log in this mail.
Thanks

PS:

Please check where your perl source is installed. In my machine, the perl is sitting in the following directory. [/usr/local/bin/perl] so I have set the path for perl like this [#!/usr/local/bin/perl -W]
The path is usually the same case in most of the machines as most of the times the perl is installed in that directory. However it's not a bad idea to check yours in case if it was set to a different path. If so, just point to the right path.
#!/usr/local/bin/perl -W

The errors you are getting are from your cgi script and not the perl script. The perl should work just fine.

Attachments