Created
November 16, 2011 12:23
-
-
Save rbirkby/1369953 to your computer and use it in GitHub Desktop.
A UK Vat Calculator written procedurally
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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