New to Php & needing function help.

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

Post Reply
pHpGirL
Forum Newbie
Posts: 3
Joined: Wed Apr 29, 2009 12:13 pm

New to Php & needing function help.

Post 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);
        }
 
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

Re: New to Php & needing function help.

Post by Mark Baker »

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

Re: New to Php & needing function help.

Post 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.
divito
Forum Commoner
Posts: 89
Joined: Sun Feb 22, 2009 7:29 am

Re: New to Php & needing function help.

Post 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);
}
}
pHpGirL
Forum Newbie
Posts: 3
Joined: Wed Apr 29, 2009 12:13 pm

Re: New to Php & needing function help.

Post by pHpGirL »

Ok, I got it working.. Sweet! Thank u!
Post Reply