Page 1 of 1

New to Php & needing function help.

Posted: Wed Apr 29, 2009 12:22 pm
by pHpGirL
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);
        }
 

Re: New to Php & needing function help.

Posted: Wed Apr 29, 2009 12:31 pm
by Mark Baker
You say it isn't working.... so what is it doing that's wrong?

Re: New to Php & needing function help.

Posted: Wed Apr 29, 2009 1:02 pm
by pHpGirL
For whatever reason its not reading the else statement. Its multiplying all the hoursworked with the hourylwage & not calculating overtime :(. I dont get it.

Re: New to Php & needing function help.

Posted: Wed Apr 29, 2009 1:08 pm
by divito
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);
}
}

Re: New to Php & needing function help.

Posted: Wed Apr 29, 2009 2:58 pm
by pHpGirL
Ok, I got it working.. Sweet! Thank u!