calculation code

I am an absolute noob so bare with me. I am trying to create a variety of calculators using similar calculations. This is the basic of what I need. If anyone can give me working code I am sure I can figure out how to do the others… yeah, right. Consider it for the greater good of mankind and world peace.

Description:
Field 1: number input field, up to 7 digits, no decimal
Field 2: percentage input field with a default value (6%) that can be changed by user
Calculation: Field 1 multiplied by Field 2, divided by 2 then multiplied by 20% = answer

Thank you all and God bless.

Hi Don

Try This

If you use a form to get your variables and then use $_get:

[php]$number = $_GET[‘number’];
$per = $_GET[‘percent’];

$answer1 = $number * $per;
$answer2 = $answer1 / 2;
$answer3 = $answer2 * 0.2;

echo $answer3;[/php]

You can test this by defining you two variables manually to start with without the form

Moderator Edit: Fixed code errors and uses of $_get (should be $_GET).

Sponsor our Newsletter | Privacy Policy | Terms of Service