PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
pHpGirL
Forum Newbie
Posts: 3 Joined: Wed Apr 29, 2009 12:13 pm
Post
by pHpGirL » Wed Apr 29, 2009 12:22 pm
I'm working on a program that calculates an employees overtime, but my overtime function isn't working! Any suggestions?
Code: Select all
function getWage($hourlyWage, $hoursWorked)
{
if ($hoursWorked <= 40)
return round(($hourlyWage * $hoursWorked), 2);
else
return round(($hourlyWage * 40) +
($hourlyWage * 1.5 * ($hoursWorked - 40)), 2);
}
Last edited by
Benjamin on Wed Apr 29, 2009 12:24 pm, edited 1 time in total.
Reason: Added php tags
Mark Baker
Forum Regular
Posts: 710 Joined: Thu Oct 30, 2008 6:24 pm
Post
by Mark Baker » Wed Apr 29, 2009 12:31 pm
You say it isn't working.... so what is it doing that's wrong?
pHpGirL
Forum Newbie
Posts: 3 Joined: Wed Apr 29, 2009 12:13 pm
Post
by pHpGirL » Wed Apr 29, 2009 1:02 pm
For whatever reason its not reading the else statement. Its multiplying all the hoursworked with the hourylwage & not calculating overtime
. I dont get it.
divito
Forum Commoner
Posts: 89 Joined: Sun Feb 22, 2009 7:29 am
Post
by divito » Wed Apr 29, 2009 1:08 pm
Should be this if I'm not mistaken.
Code: Select all
function getWage($hourlyWage, $hoursWorked)
{
if ($hoursWorked <= 40) {
return round(($hourlyWage * $hoursWorked), 2);
} else {
return round(($hourlyWage * 40) + ($hourlyWage * 1.5 * ($hoursWorked - 40)), 2);
}
}
pHpGirL
Forum Newbie
Posts: 3 Joined: Wed Apr 29, 2009 12:13 pm
Post
by pHpGirL » Wed Apr 29, 2009 2:58 pm
Ok, I got it working.. Sweet! Thank u!