I did wonder about recursion...
Spoiler:
Code:
class Program
{
static int months = 0;
static void Main(string[] args)
{
CalculateMortgage(100000f, 4.75f, 700);
Console.ReadLine();
}
static void CalculateMortgage(float mortgage,float rate,int repaymentAmount)
{
if (mortgage > 0)
{
months++;
CalculateMortgage((mortgage * (1 + ((rate / 12) / 100)) - repaymentAmount), rate, repaymentAmount);
}
else
{
Console.WriteLine("Repayment duration: " + months + " months - " + (int)(months / 12) + " Years and " + (months % 12) + " months.");
}
}
}
Result:
Repayment duration: 211 months - 17 Years and 7 months.
I'm still sure there must be an equation for it rather than just iterating through.