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>
<title>taxwagefunction.php[</title>
<?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.

wanna do that again with code tags?

My apologies. I hope this worked correctly.

``````<html>
<body>
<title>taxwagefunction.php[</title>
<?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 apologies. I hope this worked correctly.

``````<html>
<body>
<title>taxwagefunction.php[</title>
<?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;

{

[B]else [U]{[/U]
\$gross = \$payrate * \$hours;
}[/B]

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>``````

on the else I think you have missed a bracket. I have bolded it and put in the extra bracket and I have underlined the extra bracket.

I appreciate the reply. For some reason it still doesn't like something in the code. Is it my loop structure by chance? I have else, else if, if- I just wonder if I should keep it all elses or all else ifs?

I don't know where you call the function. Also the function doesn't return anything. I can't see where it ends either. Your braces look a little messed up. Without proper indenting, your code is pretty unreadable. Sorry.

hi brothers, am just new here.
i am now learning how to code, is there anyway you guys can help me develop a school management system with ,