Hello all...New to the group here. Glad to be part of the site as I just found it and am excited about learning!
Have a hopefully easy question for anyone who has the time to assist. Yes, it is for homework, so I hope I don't break any rules here. I just need assistance and it would be greatly appreciated...
I am taking an old script I had to calculate payroll taxes and I would like to turn the calculation loop I am using into its own function, function taxcalc().
After uploading to my server, I am getting errors, starting on line 20 where the first "else" comes in.
<html>
<body>
<head>
<title>taxwagefunction.php[</title>
</head>
<?php
$hours = $_POST['enter_hours'];
$payrate = $_POST['enter_RPay'];
$name = $_POST['enter_name'];
function taxcalc() {
if ($hours > 40)
$gross = $payrate * 40;
$ot = ($hours - 40) * ($payrate * 1.5);
$TotGross = $gross + $ot;
{
else
$gross = $payrate * $hours;
}
if ($gross <= 850) {
$tax = $gross * .15;
}
else if ($gross > 850 && $gross <=2060) {
$tax = $gross * .28;
}
else if ($gross > 2060 && $gross <= 3900) {
$tax = $gross * .32;
}
else {
$tax = $gross * .40;
}
$net = $gross - $tax;
echo "<p>";
echo $name, " worked ", $hours, " hours, and earned $", $TotGross, ". <br />";
echo $name, " was taxed $", $tax, " for a net pay total of $", $net, ".";
echo "</p>";
?>
</body>
</html>
My question is, how do I group the whole If/else statement as it's own function? Do I have the brackets in the wrong place or am I so far off I should scrap it and start over?
Thank you for your assistance and time.