C# tax calculation


SUBMITTED BY: Guest

DATE: Nov. 11, 2013, 9 p.m.

FORMAT: Text only

SIZE: 680 Bytes

HITS: 818

  1. decimal GetTaxes(decimal salary)
  2. {
  3. var rates = new[]
  4. {
  5. new { Threshold = 40230.0m, Rate = 0.45m },
  6. new { Threshold = 21240.0m, Rate = 0.33m },
  7. new { Threshold = 14070.0m, Rate = 0.3m },
  8. new { Threshold = 8660.0m, Rate = 0.23m },
  9. new { Threshold = 5070.0m, Rate = 0.14m },
  10. new { Threshold = 0.0m, Rate = 0.1m },
  11. };
  12. decimal tax = 0;
  13. foreach (var r in rates)
  14. {
  15. decimal slice = salary - r.Threshold;
  16. if (slice <= 0)
  17. continue;
  18. tax += r.Rate * slice;
  19. salary -= slice;
  20. }
  21. return tax;
  22. }

comments powered by Disqus