Bifalgorithm post · Computer science one · Quadratic Roots Revisited

How can conditionals prevent a calculated tax liability from becoming negative?

How can conditionals prevent a calculated tax liability from becoming negative? (Computer science one · Quadratic Roots Revisited) — "The tax program uses cond…

Ideas in this flowchart

  • PHP tax program calculates base tax, child credit, and final tax liability
  • Read the taxpayer’s adjusted gross income
  • Read the number of children
  • Check whether income and number of children are nonnegative
  • Display invalid inputs and terminate the program
  • Accept the inputs for tax calculations
  • Determine the base tax from the income bracket
  • For income up to $18,150, calculate tax at 10%
  • For income up to $73,800, calculate $1,815 plus 15% of the excess
  • For income up to $148,850, calculate $10,162.50 plus 25% of the excess
  • For income up to $225,850, calculate $28,925 plus 28% of the excess
  • For income up to $405,100, calculate $50,765 plus 33% of the excess
  • For income up to $457,600, calculate $109,587.50 plus 35% of the excess
  • For higher income, calculate $127,962.50 plus 39.6% of the excess
  • Determine the child credit from the number of children
  • For three or fewer children, calculate $1,000 per child
  • For more than three children, set the credit to $3,000
  • Compare the base tax minus the child credit with zero
  • If the difference is nonnegative, set total tax to the difference
  • If the difference is negative, set total tax to zero
  • Display AGI, base tax, credit, and final tax liability
Feed/

How can conditionals prevent a calculated tax liability from becoming negative?

No cover

Channel

Computer science one

1 page

"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"

Flowchart preview
👍
0
0 comments0 shares

Sign in to view and post comments.