Good Morning,

I'm writing a control structure elsif clause to test various arguments and display the result that meets the argument.

My clause relates to calculating the maximum total housing payment people can afford based on the income and debt information that was provided.

The key is the down payment percentage that is going to be placed for the purchase. The options on the form are: 5%, 10%, 15%, and 20%.

Anyone with a 5%, 10%, or 15% down payment, the ratio used is 28/36. Anyone with a 20% down payment, the ratio is 33/38.

To determine the maximum total housing payment affordable, the $totalpmt variable will represent the lower of the two calculations. For example: for a 20% down payment, you will use the 33/38. If the result of 33 is lower than 38; the payment should be the calculation of 33. If the result 33 greater than 38, the payment should be the calculation of 38.

At this time, my clause works correctly for anyone who puts either a 10%, 15% and 20% down payment. If someone wants to put 5% down, the result is incorrect.

At all times, the results for 5%, 10%, and 15% should be the same since they are using the same ratio of 28/36.

Please feel free to go to my form and test it yourself. The URL is:
http://www.summitwebcrafters.com/prequalification form.htm

Here's the input data:
income: 10000
auto loans: 1250
interest: 8
term: 30
Test each of the down payment percentages in the drop down box.

The result will appear in red.

The results are:
20% down = 2550
15% down = 2350
10% down = 2350
5% down = 2800 --- this is incorrect, it should be 2350 as well.

Below, is the code that I wrote to determine all this. I probably gave more information than necessary but more is better than less.

Any help you can give me in troubleshooting why 5% is not coming up with the right result is greatly appreciated.

Here's the code:
## Calculates the maximum monthly total housing payment (income / debt +) ## my $ratioincome28 = 0; my $ratioincome33 = 0; my $ratiodebt36 = 0; my $ratiodebt38 = 0; $ratioincome28 = $totalincome * .28; $ratioincome33 = $totalincome * .33; $ratiodebt36 = ($totalincome * .36) - $totaldebt; $ratiodebt38 = ($totalincome * .38) - $totaldebt; ## Determines the lower of the two ratios ## my $totalpmt = 0; if ( ($ratioincome33 gt $ratiodebt38) && ($downpercent eq 20) ) { $totalpmt = $ratiodebt38; } elsif ( ($ratioincome33 lt $ratiodebt38) && ($downpercent eq 20) ) { $totalpmt = $ratioincome33; } elsif ( ($ratioincome28 gt $ratiodebt36) && ($downpercent lt 20) ) { $totalpmt = $ratiodebt36; } else { $totalpmt = $ratioincome28; }
Thanks for all the help.

In reply to Elsif Clause Problem by b310

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.