lecture4 - CS106lecture4notes Incometaxrevisited...

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

View Full Document Right Arrow Icon
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
Image of page 1

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

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern