Need urgent help with my php program

Discussion in 'PHP' started by Luke Watson, Oct 23, 2010.

  1. #1
    Hey i'm currently developing a php console mode program for a client. It is a tax program that prompts the user the annual gross income, calculates the tax payable and then displays the gross income and mount of tax payable.

    Here is the code,

    
    #!/usr/local/bin/php -q
    <?php
    //tax.php
    require ("phpio");
    
    $gross = 0;
    $tax = 0.0;
    
    print ("\n\n Enter annual gross income: ");
    $gross = input();
    
    if ($gross >= 6001 && $gross <= 35000 )
    {
      $tax = $gross - 6000;
      $tax = $tax * 0.15;
    }
    
    if ($gross >= 35001 && $gross <= 80000)
    {
      $tax = $gross - 35000;
      $tax = $tax * 0.30;
      $tax = $tax + 4350;
    }
    
    if ($gross >= 80001 && $gross <=180000)
    {
      $tax = $gross - 80000;
      $tax = $tax * 0.38;
      $tax = $tax + 17850;
    }
    
    if ($gross >= 180001)
    {
      $tax = $gross - 180000;
      $tax = $tax * 0.45;
      $tax = $tax + 55850;
    }
    
    print ("\nGross pay is:\n");
    print ("$ $gross\n\n");
    print ("Tax payable:\n");
    print ("$ $tax\n\n ");
    ?>
    
    Code (markup):
    There is one problem with it. If the user reports tax on 35001 and it is 4350.3. But i want it to display 4350.30. How would i do this. Any help would be much appreciated.
     
    Luke Watson, Oct 23, 2010 IP
  2. shallowink

    shallowink Well-Known Member

    Messages:
    1,218
    Likes Received:
    64
    Best Answers:
    2
    Trophy Points:
    150
    #2
    shallowink, Oct 23, 2010 IP
  3. scriptinstaller

    scriptinstaller Peon

    Messages:
    109
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    or check to see if 2 digits are in decimal and if not, add a zero
     
    scriptinstaller, Oct 23, 2010 IP