View Single Post
Old 18-08-2009, 00:03   #81
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?

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.
punky is offline   Reply With Quote