Hours Calculated

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sentiald
    New Member
    • Feb 2008
    • 1

    Hours Calculated

    I am having trouble with the following code. I need to have it calculate regular pay, overtime pay and gross pay and display it back to the user. Can anyone figure out where my problem lies.
    [php]
    <?php
    //global variables
    $wage = 0;
    $hours = 0;
    $error_count = 0;
    $gross = 0;

    $error_message = array();
    ?>

    <html>
    <head>
    <title>Paycheck </title>
    <link href="paycheck. css" rel="stylesheet " type="text/css" />
    </head>

    <body>

    <h1>Paycheck</h1>

    <?php
    //user input
    retrieve_data($ wage, $hours);

    //validate
    $error_messages = validate_verify _user_input($wa ge, $hours);

    $error_count = count($error_me ssages);

    //check errors
    if($error_count > 0)
    {
    display_error_p age($error_mess ages);
    }

    else
    {
    //processing
    $gross = process_data($w age, $hours);
    display_respons e_page($wage, $hours, $gross);
    }

    exit();
    ?>

    <?php

    function retrieve_data(& $wage, &$hours)
    {
    $wage = $_GET["wage"];
    $hours = $_GET["hours"];
    }


    function validate_verify _user_input($wa ge, $hours)
    {
    $errors = array();

    if(!is_numeric( $wage) || !is_numeric($ho urs))
    {
    $errors[] = "Wage and hours must contain numeric information";
    }

    if($wage > 99.99)
    {
    $errors[] = "Wage must be less than 100%";
    }

    if($wage < .01)
    {
    $errors[] = "Wage must be greater than 0";
    }

    return $errors;
    }

    function display_error_p age($error_mess ages)
    {
    echo "<body style='backgrou nd-color:red; color:white'>";

    echo "<h3>Hit your brower's back button and correct the following input errors:</h3>";

    echo "<p class='center'> ";

    foreach($error_ messages as $error)
    {
    echo $error."<br />";
    }

    echo "</p>";

    echo "</body></html>";

    }

    function process_data($w age, $hours)
    {
    $gross = 0;
    $reg_wage = 0;
    $over_wage = 0;

    $wage = $wage * .01;

    do
    {
    $gross++;

    for($x = 0; $x < 4; $x++)
    {
    $reg_wage = ($wage * $hours);
    $over_wage = ($wage * 1.5) * $hours;
    }
    }

    return $gross;
    }

    function display_respons e_page($wage, $hours, $gross)
    {
    echo "<body>";

    echo "<h3>";

    echo "Total gross amount ";

    echo "<span class='under'>$ gross</span>";

    echo " Overtime pay $over_wage Regular pay $reg_wage ";

    echo "</h3>";

    echo "</body></html>";
    }

    ?>
    [/php]
    Last edited by ronverdonk; Feb 15 '08, 04:04 PM. Reason: enclosing code within tags
  • code green
    Recognized Expert Top Contributor
    • Mar 2007
    • 1726

    #2
    Can anyone figure out where my problem lies.
    You are not echoing out any variables so you cannot 'see' what is happening

    Comment

    • ronverdonk
      Recognized Expert Specialist
      • Jul 2006
      • 4259

      #3
      Next time enclose any code within the proper code tags. See the Posting Guidelines on how to do that.

      moderator

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

        #4
        Try to debug some: To start, put a print_r($_GET) at the top so you can see if any data is actually coming in via this array.

        Ronald

        Comment

        Working...