Bifalgorithm post · Computer science one · Life & Taxes

How can if-else-if statements calculate tax across increasing income ranges?

How can if-else-if statements calculate tax across increasing income ranges? (Computer science one · Life & Taxes) — "Next, we can code a series of if-else-if…

Ideas in this flowchart

  • Implement income-based tax calculation with an if-else-if structure.
  • Check income ranges in increasing order.
  • Because the ranges are ordered, each branch only checks an upper income bound.
  • The structure contains several income-range branches with corresponding tax formulas.
  • If income is at most 18,150, calculate baseTax as income × 0.10.
  • Else if income is at most 73,800, calculate baseTax as 1,815 + (income − 18,150) × 0.15.
  • Else if income is at most 148,850, apply the corresponding tax calculation.
  • For the final else branch, calculate baseTax as 127,962.50 + (income − 457,600) × 0.396.
Feed/

How can if-else-if statements calculate tax across increasing income ranges?

No cover

Channel

Computer science one

1 page

"Next, we can code a series of if-else-if statements for the income range. By placing the ranges in increasing order, we only need to check the upper bounds just as in the original example.\n\n1 if(income <= 18150) {\n\n2 baseTax = income * .10;\n\n3 } else if(income <= 73800) {\n\n4 baseTax = 1815 + (income - 18150) * .15;\n\n5 } else if(income <= 148850) {\n\n6 ...\n\n7 } else {\n\n8 baseTax = 127962.50 + (income - 457600) * .396;\n\n9 }"

Flowchart preview
👍
0
0 comments0 shares

Sign in to view and post comments.