Guest User

Untitled

a guest
Sep 27th, 2011
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.67 KB | None | 0 0
  1. public double GetTax(double income)
  2. {
  3.     var rules = new[] {
  4.         new { Taxable = 0, Rate = 0d },
  5.         new { Taxable = 5070, Rate = 10d },
  6.         new { Taxable = 8660, Rate = 14d },
  7.         new { Taxable = 14070, Rate = 23d },
  8.         new { Taxable = 21240, Rate = 30d },
  9.         new { Taxable = 40230, Rate = 33d },
  10.         new { Taxable = int.MaxValue, Rate = 45d }
  11.     };
  12.  
  13.     var tax = 0d;
  14.     for (var i = rules.Length - 1; i > 0; i--)
  15.     {
  16.         var taxable = income - rules[i - 1].Taxable;
  17.         if (taxable > 0d)
  18.         {
  19.             tax += taxable * rules[i].Rate / 100d;
  20.             income -= taxable;
  21.         }
  22.     }
  23.     return tax;
  24. }
  25.  
Advertisement
Add Comment
Please, Sign In to add comment