2 Replies - 3471 Views - Last Post: 07 February 2011 - 05:01 PM Rate Topic: -----

#1 allenb_3  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 07-February 11

Paycheck calculator in PHP

Posted 07 February 2011 - 01:41 PM

I wrote this paycheck calculator program in PHP. The numbers were taken from the IRS website and my current paycheck for as much accuracy as possible.
It doesn't give me an error when I run it. It just says I made like $-63930 for the week. So it has to be something in my logic, but my logic seems correct to me. Any suggestions?


<?php
  $hours = $_POST["hours"];
  $rate = $_POST["rate"];
  $name = $_POST["name"];
  $gross = $hours * $rate;  
  echo $name.', you worked '.$hours.' hours at a rate of $'.$rate.' per hour. <br />';
  if($gross > 40 && $gross <= 204)    
    $ftax = 0.00 + ($gross * 0.10);
  else if($gross > 205 && $gross <= 704)
    $ftax = 16.40 + ($gross * 0.15);
  else if($gross > 704 && $gross <= 1648)
    $ftax = 91.40 + ($gross * 0.25);
  else if($gross > 1648 && $gross <= 3394)
    $ftax = 327.40 + ($gross * 0.28);
  else if($gross > 3394 && $gross <= 7332)
    $ftax = 816.28 + ($gross * 0.33);
  else if($gross > 7332)
    $ftax = 2115.82 + ($gross * 0.35);  
  else 
    $ftax = 0;
    
    $stax = 17.86;
    $sstax = 0.042;
    $medicare = 0.0145;
    $ftax = $gross * $ftax;
    $stax = $gross * $stax;
    $sstax = $gross * $sstax;
    $medicare = $gross * $medicare;

  
  if($hours > 40)                                                         
  {
    $remainder = $hours - 40;
    $overtime = $gross + $remainder * ($rate * 1.5);
    $net = $overtime - $ftax - $stax - $sstax - $medicare;
    echo 'Well '.$name.', looks like you made $'.$net.' this week.';
  }
  else     
  {
    $net = $gross - $ftax - $stax - $sstax - $medicare;
    echo 'Well '.$name.', looks like you made $'.$net.' this week.';
  }

This post has been edited by Dormilich: 08 February 2011 - 12:30 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Paycheck calculator in PHP

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6110
  • View blog
  • Posts: 23,670
  • Joined: 23-August 08

Re: Paycheck calculator in PHP

Posted 07 February 2011 - 02:51 PM

Please post your posts in PHP. This is not at ALL database related.

Moved to PHP.
Was This Post Helpful? 0
  • +
  • -

#3 Valek  Icon User is offline

  • The Real Skynet
  • member icon

Reputation: 543
  • View blog
  • Posts: 1,713
  • Joined: 08-November 08

Re: Paycheck calculator in PHP

Posted 07 February 2011 - 05:01 PM

You've got state tax as 17.86, and your federal tax is usually a massive positive value. Multiplying your gross by either of those values is going to give you a huge number that will cause you to always receive a huge negative value.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1