Help with a calculation
hjaber
created: 2006-02-03 13:15:52
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 <

Patton Industries


Bonus Calculation


Sales Person: $salesperson
Sales: $sales
here foreach $k(@rates) { $newrates = ($rates2{$k}) * 100; $commission = ($sales * ($rates2{$k})); printf "Using a rate of %.1f%%, \n", $newrates; print "your bonus is $commission
\n"; } print "\n"; print "\n";
Result code should look like this:


Patton Industries


Bonus Calculation


Sales Person: John Doe
Sales: $1000.00
Using a rate of 5.0%, your bonus is $50.000
Using a rate of 6.0%, your bonus is $60.000
Using a rate of 7.0%, your bonus is $70.000
I really appreciate your help. If you require further information, please let me know. Thanks, Hatem Jaber
Re: Help with a calculation
created: 2006-02-03 13:23:17
I bet it has something to do with this warning:

Argument "$10000.00" isn't numeric in multiplication (*) at ./script line 40..

Re^2: Help with a calculation
created: 2006-02-04 08:10:27
I don't understand what you mean, can you be more clear? Programming with Perl is new to me and I am not totally clear on your suggestion. Thanks, Hatem Jaber
Re^3: Help with a calculation
created: 2006-02-04 09:02:07

In this line:

$sales = sprintf "\$%.2f", param('Sales');

your $sales variable will end up containing a dollar sign plus whatever value comes from the 'Sales' parameter. Perl will treat this as a string, not a number...

Re^4: Help with a calculation
created: 2006-02-04 11:52:03
That makes sense now, thank you for your help. I made the changes and now everything is working great. Thanks again for your help! Hatem Jaber

perlmonks.org content © perlmonks.org and hjaber, john_oshea, saintmike

prlmnks.org © 2006 edmund von der burg (eccles & toad)

v 0.03