View Single Post
Old 17-08-2009, 23:33   #79
punky
Inactive
 
Join Date: Jun 2003
Age: 44
Posts: 14,750
punky has a golden aurapunky has a golden aura
punky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aura
Re: Programming Challenges?

Here's my mortgage length calculator:

Spoiler: 

I'm sure there's a way to do it without a loop, but can't think of it atm.

Assuming £100,000 with a 4.75% rate and paying off £700/month
Code:
            float mortgage = 100000f;
            float rate = 4.75f; //%
            int repaymentAmount = 700;

            float months = 0;

            while (mortgage > 0)
            {
                mortgage *= (1 + ((rate / 12) / 100));
                mortgage -= repaymentAmount;
                months++;
            }

            Console.WriteLine("Repayment duration: " + months + " months - " + (int)(months/12) + " Years and " + (months%12) + " months.");
Result:

Repayment duration: 211 months - 17 Years and 7 months.
punky is offline   Reply With Quote