{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lecture4

# lecture4 - CS106lecture4notes Incometaxrevisited...

This preview shows pages 1–2. Sign up to view the full content.

CS 106 lecture 4 notes Income tax revisited A standard C type of solution: In this, we start at the top of the tax brackets and work down until the currentBracket (the counter) is at 0. At each step we check if our remaining income is greater than the lower bound of the bracket and tax the amount above that bound at the tax bracket amount. That taxed income is removed from our income and we continue. Try working it with \$80,000 income. function tax = computeTax(income) % Computes income tax for a graduated tax system using % traditional programming style % Put brackets into brackets array in function starting with 0 % Put tax rates into taxrate array in function starting with lowest tax rate % Call function with income as input argument brackets = [0 7300 29700 71950 150150 326450]; taxrate = [10 15 25 28 33 35] tax = 0; %start at top bracket and work down currentBracket = length(brackets); remainingIncome = income; while currentBracket > 0 if remainingIncome > brackets(currentBracket); tax = tax + taxrate(currentBracket)*(remainingIncome - brackets(currentBracket))/100.0; remainingIncome = brackets(currentBracket); end % move down to next bracket

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 5

lecture4 - CS106lecture4notes Incometaxrevisited...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online