I need urgent php help!

farcry51

Member
Joined
Oct 24, 2010
Messages
4
Kin
0💸
Kumi
0💴
Trait Points
0⚔️
Hey guys i know this may be stupid considering this is my first post xd but my friend told me that there are some IT whizzes on here so i've come to ask for help.

My homework was to develop a tax console mode program that prompts the user for the annual gross income, calculates the tax payable and then displays the gross income and amount of tax payable.

Here is my code,

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 ");
?>
There is one problem with it. If the user reports tax on 35001 the answer equals 4350.3. But i want it to display 4350.30. Can someone edit my code for me and tell me how to do it?

Many thanks.
 

gamahiro

Active member
Supreme
Joined
Jul 8, 2010
Messages
32,579
Kin
0💸
Kumi
0💴
Trait Points
0⚔️
Awards
Instead of:
Code:
print ("$ $tax\n\n ");
Try:
Code:
printf ("%01.2f", $tax);
That's all I can think of off the top of my head. If that doesn't work, let me know and I'll dig out my old notes.
 
Top