Concept
How can conditionals prevent a calculated tax liability from becoming negative?
ComputerScienceOne / Quadratic Roots Revisited
"The tax program uses conditional statements to calculate a taxpayer’s base tax, child credit, and final tax liability. If the base tax minus the credit is greater than or equal to zero, the total tax is set to that difference; otherwise, the total tax is set to zero.\n\n1 <?php\n\n2 //prompt for income from the user\n\n3 printf(\"Please enter your Adjusted Gross Income: \");\n\n4\n\n5 $income = floatval(trim(fgets(STDIN)));\n\n6\n\n7 //prompt for children\n\n8 printf(\"How many children do you have? \");\n\n9 $numChildren = intval(trim(fgets(STDIN)));\n\n10\n\n11 if($income < 0 || $numChildren < 0) {\n\n12 printf(\"Invalid inputs\");\n\n13 exit(1);\n\n14 }\n\n15\n\n16 if($income <= 18150) {\n\n17 $baseTax = $income * .10;\n\n18 } else if($income <= 73800) {\n\n19 $baseTax = 1815 + ($income -18150) * .15;\n\n20 } else if($income <= 148850) {\n\n21 $baseTax = 10162.50 + ($income - 73800) * .25;\n\n22 } else if($income <= 225850) {\n\n23 $baseTax = 28925.00 + ($income - 148850) * .28;\n\n24 } else if($income <= 405100) {\n\n25 $baseTax = 50765.00 + ($income - 225850) * .33;\n\n26 } else if($income <= 457600) {\n\n27 $baseTax = 109587.50 + ($income - 405100) * .35;\n\n28 } else {\n\n29 $baseTax = 127962.50 + ($income - 457600) * .396;\n\n30 }\n\n31\n\n32 if($numChildren <= 3) {\n\n33 $credit = $numChildren * 1000;\n\n34 } else {\n\n35 $credit = 3000;\n\n36 }\n\n37\n\n38 if($baseTax - $credit >= 0) {\n\n39 $totalTax = $baseTax - $credit;\n\n40 } else {\n\n41 $totalTax = 0;\n\n42 }\n\n43\n\n44 printf(\"AGI: $%10.2f\n\n\", $income);\n\n45 printf(\"Tax: $%10.2f\n\n\", $baseTax);\n\n46 printf(\"Credit: $%10.2f\n\n\", $credit);\n\n47 printf(\"Tax Liability: $%10.2f\n\n\", $totalTax);\n\n48\n\n49 ?> Code Sample 38.3.: Tax Program in PHP"
Related Ideas
- How is the child tax credit calculated and limited by total tax liability?ComputerScienceOne · Life & Taxes
- How can PHP conditionals validate income and calculate life and taxes?ComputerScienceOne · Life & Taxes
- How can conditionals calculate tax brackets, credits, and total tax?ComputerScienceOne · Quadratic Roots Revisited
- How can conditional statements be used to build a life and taxes program?ComputerScienceOne · Life & Taxes
- How can if-else-if statements calculate tax across increasing income ranges?ComputerScienceOne · Life & Taxes
- How do if, if-else, and if-else-if statements work in PHP?ComputerScienceOne · If, If-Else, If-Else-If Statements
- How can a Java program read income and children inputs while rejecting negative values?ComputerScienceOne · Life & Taxes
- How are if, if-else, and if-else-if statements written in C?ComputerScienceOne · If, If-Else, If-Else-If Statements