[RESOLVED] Using PHP to calculate a paycheck - issues with doing this
Results 1 to 3 of 3

Thread: [RESOLVED] Using PHP to calculate a paycheck - issues with doing this

  1. #1
    Junior Member
    Join Date
    Oct 2009
    Posts
    3

    resolved [RESOLVED] Using PHP to calculate a paycheck - issues with doing this

    I am very new to PHP. Right now we are working with functions and control structures. I have an assignment where I have to calculate earnings based on wage, hours, and potential overtime over 40 hours at 1.5.

    There are no examples in my text at this point that I can follow from for direction and at this point I am going blind.

    Can someone please provide assistance or direction on what I should be doing? As of now, all I am getting are errors.

    paycheck.html code:

    Code:
    !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Paycheck Calculator</title>
    <meta http-equiv="Content-Type"
    	content="text/html; charset=iso-8859-1" />
    </head>
    <body>
    	<table>
        <tr>
        </tr>
        <tr>
            <td><h1>Paycheck Calculator</h1></td>
        </tr>
        <tr>
            
    
        </tr>
    </table>
    <hr />
    	
    	<form method="get" action="Paycheck.php">
    	    <p>Hours worked:
    	    <input type="text" name="hours" id="hours" />
    	    </p>
    	    <p>Employee wage:
    	    <input type="text" name="wage" id="wage" /><br /><br />
    	    <input type="submit" />
    	    </p>
    
    	</form>
    </body>
    </html>
    paycheck.php code:
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Paycheck Results</title>
    <meta http-equiv="Content-Type"
    	content="text/html; charset=iso-8859-1" />
    <link rel="stylesheet" href="php_styles.css" type="text/css" />
    </head>
    <body>
    <h1>Paycheck Calculations</h1>
    <?php
    
    $hoursWorked = $_GET["hours"];
    $wages = $_GET["wage"];
    $x = $hoursWorked;
    $y = $wages;
    $z = $pay;
    
    if ($x is <= 40){
    $submit = ("$z = $x * $y")
    echo "Your Paycheck is: $payCheck";
    }
    
    if ($x is > 40){
    $submit = ("$z = ($x *$y) + (($x - 40) * $y * 1.5")
    echo "Your Paycheck is: $payCheck";
    }
    
    ?>
    </body>
    </html>
    Any assistance would be greatly appreciated.

  2. #2
    High Energy Magic Dept. NogDog's Avatar
    Join Date
    Aug 2006
    Location
    Ankh-Morpork
    Posts
    13,943
    In the two IF conditions, get rid of the word "is" before the comparison operators. Also, in the code that follows each condition, you forgot the ";" at the end of the lines where you do your arithmetic.

    PS: You can make your PHP code easier to read here by wrapping it in [php]...[/php] tags (instead of [code]), as they add contextual colored highlighting.
    Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be." ~ from Nation, by Terry Pratchett

    "But the main reason that any programmer learning any new language thinks the new language is SO much better than the old one is because hes a better programmer now!" ~ http://www.oreillynet.com/ruby/blog/...ck_to_p_1.html


    eBookworm.us

  3. #3
    Buzz PHP Class Library BuzzPHP's Avatar
    Join Date
    Jul 2009
    Location
    Adelaide
    Posts
    102
    Cool project. try to keep things simple and learn some of the globally used maths functions like max, min, abs... etc. Just about every language has these basic functions, so learning these will do you good for the future.


    PHP Code:
    <html><head><title>Paycheck Results</title></head>
    <body>
    <h1>Paycheck Calculations</h1>

    <?php
    $hours 
    = (int) $_GET["hours"];
    $wages = (int) $_GET["wage"];

    $overtime max($hours 400);
    $pay += $overtime $wages 1.5;
    $pay += ($hours $overtime) * $wages;

    echo 
    "Hours Worked: " $hours "<br>";
    echo 
    "Pay rate (per hour): $" number_format($wages2) . "<br>";
    echo 
    "Overtime Hours: " $overtime "<br>";
    echo 
    "Your Paycheck is: $" number_format($pay2) . "<br>";
    ?>
    </body>
    </html>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •