Working on a class assignment and when I run this code
function paycheck1($hours,$payrate,$othours,$otrate){
if ($hours > $othours){
$total = "<tr><td>".($hours*$payrate)+($hours - $othours)*$otrate."</td></tr>";
return $total;
}
else{
$total = "<tr><td>".$hours * $payrate."</td></tr>";
return $total;
}
}
$pay = 10;
$hours = 50;
$overtime_starts = 40;
$overtime_rate = 15;
echo "<table>";
for ($i=0;$i<$hours;$i++){
echo paycheck1($i, $pay, $overtime_starts, $overtime_rate);
}
echo "</table>";
I get output like this
153045607590105120135
0
10
20
30
40.....
Why am I getting 153045607590105120135 When I run the code. If I remove the ($hours*$payrate)+ from the function->if it works just fine. Why am I getting what I use is an overflow error.
It’s easier to find the problem in the source if you put newlines at the end of your html, like:
Also, you have to pay attention to the order of operations, even with the
.operator.This line:
Needs parenthesis: