8 Replies - 270 Views - Last Post: 13 May 2014 - 03:56 PM Rate Topic: -----

#1 chaos1973  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 80
  • Joined: 30-January 12

trying to calculate payrate

Posted 13 May 2014 - 12:40 PM

This is the code my teacher gave me and I need to modify it with 2 functions and have it display the ouput from the user entering the information. ne help? ath the bottom is a screen shot of what i nd to do?

<?php

  function calcPay($hours, $payRate, &$regPay, &$otPay, &$totalPay)
  {
    if ($hours < 40)
    {
      $regPay = $payRate * $hours;
      $otPay = 0;
    }
    else
    {
      $regPay = $payRate * 40;
      $otPay = $payRate * 1.5 * ($hours - 40);
    }
    $totalPay = $regPay + $otPay;
  }

  $regPay = 0;
  $otPay = 0;
  $totalPay = 0;
  $hours = 0;
  $payRate = 0;
  
  if (count($_POST) > 0)
  {
	$hours = (double)$_POST["hours"];
	$payRate = (double)$_POST["payRate"];
	calcPay($hours, $payRate, $regPay, $otPay, $totalPay);
  }

?>

<html>
  <head>
  </head>
  
  <body>
    <form id="payForm" name="payForm" method="post" action="payLab6Start.php">
      <p>Enter your pay rate:  
        <input type="text" id="payRate" name="payRate" value="<?php echo $payRate // echo the pay rate here ?>"/>
      </p>
      <p>Enter the hours worked:  
        <input type="text" id="hours" name="hours" value="<?php echo $hours// echo the hours here ?>"/>
      </p>
      <p>
        <input type="submit" value="Calculate Your Pay" />
      </p>
    </form>
	<p>
	<?php 
		if (count($_POST) > 0)
		{
			echo "Hours: " . $hours . "<br />";
			echo "Pay Rate: " . $payRate . "<br />";
			echo "Regular Pay: " . $regPay . "<br />";
			echo "Overtime Pay: " . $otPay . "<br />";
			echo "Total Pay: " . $totalPay . "<br />";
		}
	?>
	</p>
  </body>
</html>

Attached image(s)

  • Attached Image

This post has been edited by chaos1973: 13 May 2014 - 01:08 PM


Is This A Good Question/Topic? 0
  • +

Replies To: trying to calculate payrate

#2 ArtificialSoldier  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 368
  • View blog
  • Posts: 1,323
  • Joined: 15-January 14

Re: trying to calculate payrate

Posted 13 May 2014 - 12:57 PM

It looks like it's already doing that, what do you need help with?
Was This Post Helpful? 0
  • +
  • -

#3 chaos1973  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 80
  • Joined: 30-January 12

Re: trying to calculate payrate

Posted 13 May 2014 - 01:05 PM

View PostArtificialSoldier, on 13 May 2014 - 12:57 PM, said:

It looks like it's already doing that, what do you need help with?



yes I saw that it does work just uploaded actual directions.
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9094
  • View blog
  • Posts: 34,148
  • Joined: 12-June 08

Re: trying to calculate payrate

Posted 13 May 2014 - 01:08 PM

Quote

ne help?

Explain this, because - right now - it sounds like you want folks to just do the work for you. What have you tried? What have you thought about?
Was This Post Helpful? 0
  • +
  • -

#5 ArtificialSoldier  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 368
  • View blog
  • Posts: 1,323
  • Joined: 15-January 14

Re: trying to calculate payrate

Posted 13 May 2014 - 01:09 PM

So he wants you to add validation? What part of that do you need help with? He doesn't really say what should happen if the validation fails.
Was This Post Helpful? 0
  • +
  • -

#6 chaos1973  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 80
  • Joined: 30-January 12

Re: trying to calculate payrate

Posted 13 May 2014 - 01:32 PM

View Postmodi123_1, on 13 May 2014 - 01:08 PM, said:

Quote

ne help?

Explain this, because - right now - it sounds like you want folks to just do the work for you. What have you tried? What have you thought about?


for one chief, slow down and for second I have tried this

if($payRate >= 10 && $payRate <= 200) {
				echo "\t\tPay Rate: \t\t\$" . $payRate . "<br />\n";
				} else {
					echo "\t\tPay Rate: \t\t\$" . $payRate ." Exceeds Minimum or Maximum amount per hour. Must be at least $10 but no more than $200.<br/>\n";


and this

if($hours > 0 && $hours < 80) {				
				echo "\tHours: \t\t\t" . $hours . " hrs.<br />\n";
				} else {
					echo "\tHours: \t\t\t" . $hours . " hrs. Exceeds Minimum or Maximum number of hours permitted. Must be at least 1 but less than 80.<br/>\n";

and here is the code as it stands and I still havent figured out the 2 decimal places and something else forgot.....
<?php

  function calcPay($hours, $payRate, &$regPay, &$otPay, &$totalPay)
  {
    if ($hours < 40)
    {
      $regPay = $payRate * $hours;
      $otPay = 0;
    }
    else
    {
      $regPay = $payRate * 40;
      $otPay = $payRate * 1.5 * ($hours - 40);
    }
    $totalPay = $regPay + $otPay;
  }

  $regPay = 0;
  $otPay = 0;
  $totalPay = 0;
  $hours = 0;
  $payRate = 0;
  
  if (count($_POST) > 0)
  {
	$hours = (double)$_POST["hours"];
	$payRate = (double)$_POST["payRate"];
	calcPay($hours, $payRate, $regPay, $otPay, $totalPay);
  }

?>

<html>
  <head>
  </head>
  
  <body>
    <form id="payForm" name="payForm" method="post" action="payStart.php">
      <p>Enter your pay rate:&nbsp;&nbsp;
        <input type="text" id="payRate" name="payRate" value="<?php
		echo $payRate // echo the pay rate here ?>"/>
      </p>
      <p>Enter the hours worked:&nbsp;&nbsp;
        <input type="text" id="hours" name="hours" value="<?php 
		echo $hours // echo the hours here ?>"/>
      </p>
      <p>
        <input type="submit" value="Calculate Your Pay" />
      </p>
    </form>
	<p>
	<?php 
		if (count($_POST) > 0)
		if($hours > 0 && $hours < 80) 
		{				
			echo "\tHours: \t\t\t" . $hours . " hrs.<br />\n";
		} 
		else 
		{
			echo "\tHours: \t\t\t" . $hours . " hrs. Exceeds Minimum or Maximum number of hours permitted.Must be at least 1 but less than 80.<br/>\n";
		}
		{
			echo "Hours: " . $hours . "<br />";
			echo "Pay Rate: " . $payRate . "<br />";
			echo "Regular Pay: " . $regPay . "<br />";
			echo "Overtime Pay: " . $otPay . "<br />";
			echo "Total Pay: " . $totalPay . "<br />";
		}
		if($payRate >= 10 && $payRate <= 200) 
		{
			echo "\t\tPay Rate: \t\t\$" . $payRate . "<br />\n";
		} 
		else 
		{
			echo "\t\tPay Rate: \t\t\$" . $payRate ." Exceeds Minimum or Maximum amount per hour.Must be at least $10 but no more than $200.<br/>\n";
		}
		
	?>
	</p>
  </body>
</html>


and here is the output so far..

Attached image(s)

  • Attached Image

Was This Post Helpful? 0
  • +
  • -

#7 chaos1973  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 80
  • Joined: 30-January 12

Re: trying to calculate payrate

Posted 13 May 2014 - 01:41 PM

View PostArtificialSoldier, on 13 May 2014 - 01:09 PM, said:

So he wants you to add validation? What part of that do you need help with? He doesn't really say what should happen if the validation fails.

yes she wants some validation of some sort and to display like this pic below and to have decimal places and error messages for bad input or no input entered. i think......and the other one is with bad input but still no decimal or $ signs and no error message if nothing entered?

Attached image(s)

  • Attached Image
  • Attached Image

This post has been edited by chaos1973: 13 May 2014 - 01:43 PM

Was This Post Helpful? 0
  • +
  • -

#8 ArtificialSoldier  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 368
  • View blog
  • Posts: 1,323
  • Joined: 15-January 14

Re: trying to calculate payrate

Posted 13 May 2014 - 03:21 PM

Just take it one step at a time. You can use number_format, for example, to format the number for printing:

http://www.php.net/m...mber-format.php
Was This Post Helpful? 1
  • +
  • -

#9 chaos1973  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 80
  • Joined: 30-January 12

Re: trying to calculate payrate

Posted 13 May 2014 - 03:56 PM

<!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>Pay</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" type="text/css" href="PayStart.css">
</head>
</html>
<?php

  function calcPay($hours, $payRate, &$regPay, &$otPay, &$totalPay)
  {
  if ($hours < 40)
    {
      $regPay = $payRate * $hours;
      $otPay = 0;
    }
    else
    {
      $regPay = $payRate * 40;
      $otPay = $payRate * 1.5 * ($hours - 40);
    }
    $totalPay = $regPay + $otPay;
	$totalPay = round($totalPay, 2);
	 }

  $regPay = 0;
  $otPay = 0.00;
  $totalPay = 0;
  $hours = 0;
  $payRate = 0;
 
 if (count($_POST) > 0)
  {
	$hours = (double)$_POST["hours"];
	$payRate = (double)$_POST["payRate"];
	calcPay($hours, $payRate, $regPay, $otPay, $totalPay);
  }

?>

<html>
  <head>
  </head>
  
  <body>
    <form id="payForm" name="payForm" method="post" action="payStart.php">
      <p>Enter your pay rate:&nbsp;&nbsp;
        <input type="text" id="payRate" name="payRate" value="<?php echo $payRate ?>"/>
      </p>
      <p>Enter the hours worked:&nbsp;&nbsp;
        <input type="text" id="hours" name="hours" value="<?php echo $hours ?>"/>
      </p>
      <p>
        <input type="submit" value="Calculate Your Pay" />
      </p>
    </form>
	<p>
	<?php 
		$hours = number_format($hours, 2, '.', '');
		$payRate = number_format($payRate, 2, '.', '');
		$regPay = number_format($regPay, 2, '.', '');
		$otPay = number_format($otPay, 2, '.', '');
		$totalPay = number_format($totalPay, 2, '.', '');
		
		if (count($_POST) > 0)
		{
			if($hours > 0 && $hours < 80)
			{				
				echo "Hours: " . $hours . " hrs.<br />";
			}
				else 
				{
					echo "Hours: " . $hours . "  -Hours must be at least 1 but less than 80.<br/>\n";
					$hours = "";
					$payrate = "";
					$regPay = "";
					$otPay = "";
					$totalPay = "";
				}
			if($payRate >= 10 && $payRate <= 200)
			{
				echo "Pay Rate: $" . $payRate . "<br />";
			}
				else 
				{
					echo "Pay Rate: $" . $payRate ." -Pay rate must be at least $10 but no more than $200.<br/>\n";
					$hours = "";
					$payrate = "";
					$regPay = "";
					$otPay = "";
					$totalPay = "";
				}
			echo "Regular Pay:$" . $regPay . "<br />";
		
		if ($otPay == 0)
			{
				$otPay = "0.00";
			}
			echo "Overtime Pay: $" . $otPay . "<br />";
			echo "Total Pay: $" . $totalPay . "<br />";
			
		}
	?>
	</p>
  </body>
</html>

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1