Skip to content

Instantly share code, notes, and snippets.

@NoelKennedy
Forked from flq/tax.cs
Created September 22, 2011 16:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NoelKennedy/1235276 to your computer and use it in GitHub Desktop.
Save NoelKennedy/1235276 to your computer and use it in GitHub Desktop.
the tax thingy
public static decimal GetTaxes(decimal salary)
{
var taxBands = new[]
{
new Tuple<Decimal, Decimal, Decimal>(0, 5070, 0.1m),
new Tuple<Decimal, Decimal, Decimal>(5070, 8660, 0.14m),
new Tuple<Decimal, Decimal, Decimal>(8660, 14070, 0.23m),
new Tuple<Decimal, Decimal, Decimal>(14070, 21240, 0.3m),
new Tuple<Decimal, Decimal, Decimal>(21240, 40230, 0.33m),
new Tuple<Decimal, Decimal, Decimal>(40230, Decimal.MaxValue, 0.45m)
};
return taxBands.Aggregate(0.0m, (taxOwed, taxband) =>
{
if (salary < taxband.Item1)
return taxOwed;
if (salary < taxband.Item2)
return taxOwed + ((salary - taxband.Item1) * taxband.Item3);
return taxOwed + ((taxband.Item2 - taxband.Item1) * taxband.Item3);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment