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]