By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,751 Members | 1,216 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,751 IT Pros & Developers. It's quick & easy.

Hours Calculated

P: 1
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($wage, $hours);

$error_count = count($error_messages);

//check errors
if($error_count > 0)
{
display_error_page($error_messages);
}

else
{
//processing
$gross = process_data($wage, $hours);
display_response_page($wage, $hours, $gross);
}

exit();
?>

<?php

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


function validate_verify_user_input($wage, $hours)
{
$errors = array();

if(!is_numeric($wage) || !is_numeric($hours))
{
$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_page($error_messages)
{
echo "<body style='background-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($wage, $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_response_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]
Feb 15 '08 #1
Share this Question
Share on Google+
3 Replies


code green
Expert 100+
P: 1,726
Can anyone figure out where my problem lies.
You are not echoing out any variables so you cannot 'see' what is happening
Feb 15 '08 #2

ronverdonk
Expert 2.5K+
P: 4,258
Next time enclose any code within the proper code tags. See the Posting Guidelines on how to do that.

moderator
Feb 15 '08 #3

ronverdonk
Expert 2.5K+
P: 4,258
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
Feb 15 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.