The code below is working great all except for the calculation to figure the commission. If on the html form you select 5%, 6%, 7%, it should loop through listing all the values or whatever values selected and calculate the commission (example: 5% * $1000.00 = $50.00). Like I said, everything is working except for the result of the calculation.
#! /perl/bin/perl #c04ex6.cgi - calculates the total price of widgets purchased print "Content-type: text/html\n\n"; use CGI qw(:standard); use CGI::Carp qw(fatalsToBrowser); #prevent Perl from creating undeclared variables use strict; #declare variables my ($salesperson, $sales, $k, $commission, $percentage, $newrates); my %rates2 = ("0", .05, "1", .06, "2", .07); my @rates = param('Rate'); #assign values to variables $salesperson = param('Salesperson'); $sales = sprintf "\$%.2f", param('Sales'); #calculate total ordered and total sale #create Web page print <<here; <html> <head> <title>Patton Industries</title> </head> <body> <h2>Bonus Calculation</h2> <br> <strong>Sales Person:</strong> $salesperson<br> <strong>Sales:</strong> $sales<br> here foreach $k(@rates) { $newrates = ($rates2{$k}) * 100; $commission = ($sales * ($rates2{$k})); printf "<strong>Using a rate of </strong>%.1f%%, \n", $newrates +; print "<strong>your bonus is </strong>$commission<br>\n"; } print "</body>\n"; print "</html>\n";
Result code should look like this:
<html> <head> <title>Patton Industries</title> </head> <body> <h2>Bonus Calculation</h2> <br> <strong>Sales Person:</strong> John Doe<br> <strong>Sales:</strong> $1000.00<br> <strong>Using a rate of </strong>5.0%, <strong>your bonus is $50.00</strong>0<br> <strong>Using a rate of </strong>6.0%, <strong>your bonus is $60.00</strong>0<br> <strong>Using a rate of </strong>7.0%, <strong>your bonus is $70.00</strong>0<br> </body> </html>
I really appreciate your help. If you require further information, please let me know. Thanks, Hatem Jaber

In reply to Help with a calculation by hjaber

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.