Jump to content

Recommended Posts

A simple math problem, but I can't get it working. If I enter 50 for $hours and 10 for $hourly I keep getting 400 $weekPay. It refuses to calculate OT pay. I don't understand what's wrong.

 

<?php

$name = $_POST['employeeName'];

$hours = $_POST['hoursWorked'];

$hourly = $_POST['hourlyPay'];

 

echo "<p>Week pay for $name \n</p>";

echo "<p>Hours worked: $hours \n</p>";

echo "<p>Pay rate: $hourly \n</p>";

 

if ($hours > 40)

{

$otHours = $hours - 40;

echo "<p>OT Hours: $otHours\n</p>";

$weekPay = (($hourly * 40) + (1.5 * hourly) * otHours);

}

else

$weekPay = $hours * $hourly;

 

echo "<p>Week pay: $weekPay </p>";

?>

Link to comment
https://forums.phpfreaks.com/topic/274901-simple-math-problem/
Share on other sites

Turn on error reporting and you'd get: 

Notice: Use of undefined constant hourly - assumed 'hourly'

 

which evals to 0.

 

You've got another one too. 

 

A decent editor with syntax highlighting makes it obvious as well.

Edited by Jessica
Link to comment
https://forums.phpfreaks.com/topic/274901-simple-math-problem/#findComment-1414746
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.