Skip to content

Instantly share code, notes, and snippets.

@rbirkby
Created November 16, 2011 12:23
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 rbirkby/1369953 to your computer and use it in GitHub Desktop.
Save rbirkby/1369953 to your computer and use it in GitHub Desktop.
A UK Vat Calculator written procedurally
using System;
class Program {
static void Main() {
WriteAmount(new DateTime(2008, 11, 01), 1.00M);
WriteAmount(new DateTime(2009, 01, 01), 1.00M);
WriteAmount(new DateTime(2010, 12, 01), 1.00M);
WriteAmount(new DateTime(2011, 12, 01), 1.00M);
}
static void WriteAmount(DateTime date, decimal exVatAmount) {
Console.WriteLine(string.Format("On {0:D}, for an amount of {1:c} the VAT inclusive figure is {2:c} for a rate of {3:p}", date, exVatAmount, CalculateAmount(date, exVatAmount), GetVat(date)));
}
static decimal GetVat(DateTime date) {
if(date < new DateTime(2008, 12, 1)) {
return 0.175M;
} else if(date < new DateTime(2010, 1, 1)) {
return 0.15M;
} else if(date > new DateTime(2011, 1, 4)) {
return 0.2M;
} else {
return 0.175M;
}
}
static decimal CalculateAmount(DateTime date, decimal exVatAmount) {
if(date < new DateTime(2008, 12, 1)) {
return exVatAmount * 1.175M;
} else if(date < new DateTime(2010, 1, 1)) {
return exVatAmount * 1.15M;
} else if(date > new DateTime(2011, 1, 4)) {
return exVatAmount * 1.2M;
} else {
return exVatAmount * 1.175M;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment