Calculations coming out wrong

Posted on 2007-10-03
Last Modified: 2010-03-05
I am working on making a car calculator for loans, I have:

print "Content-type:text/html \n\n";
use CGI qw(:standard);

my $cost       =    param('cost')     || '0.00';
my $payment    =    param('payment')  || '0.00';
my $interest   =    param('interest') || '0.10';
my $down       =    param('down')     || ($cost * 0.20);
my $loan       =    param('loan')     || '5.00';

my $due        =    ($cost - $down) * (1 + $loan * $interest / 100);

my $month      =    $due / (12 * $loan);

# if nothing default values below

# print output of all entered values

my $output = <<_END_;

<b>Cost:</b> $cost <br />
<b>Payment:</b> $payment <br />
<b>Interest:</b> $interest <br />
<b>Down:</b> $down <br />
<b>Loan:</b> $loan <br />
<br /><br />
<b>Amount due each month:</b> $month

print $output;

And I am getting the wrong output for the monthly amount due. Any suggestions on what I can do to fix the output, it is coming out very large.



    LVL 48

    Expert Comment

    Given that this is an assignment question, we can only offer pointers.

    My tip is for you to read through perlop

    perldoc perlop

    LVL 84

    Expert Comment

    If you are getting the wrong output, what would be the correct output?
    What is the relationship between $month and $loan?
    LVL 1

    Author Comment

    This isnt an assignment one, it is being hosted on the Champlains server, I did read that you can only handle pointers for assignment questions and that is perfectly fine with me. This is an extra case study I am doing out of the book, the class is kicking my butt, haha.

    I will take a look at that, what you said above.

    $month is how much you are going to pay a month
    $loan is how many years you want a loan for

    Sorry, I should have made that clear for you guys.


    LVL 28

    Expert Comment

    LVL 1

    Author Comment

    I am using what is given the extra case study I am doing for the heck of it. That is what they gave me for it.

    LVL 17

    Expert Comment

    Have a look at my last post to your other question {http://Q_22868164}
    LVL 17

    Accepted Solution

    Well, that didn't work (how do you use the EE macros, anyway?).  Anyway, the link to the prior question is:

    And I'm talking about comment ID 20013886...

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
    A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (,  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now