Compound Interest

Compound interest is the addition of interest to the principal sum of a loan or deposit, or in other words, interest on interest.


Write a program to Calculates Compound Interest.

Solution:

using System;

namespace CompoundInterset
{
    class Program
    {
        static void Main()
        {
            Console.WriteLine("Enter the Loan Total Amount:");
            var amount = Convert.ToDouble(Console.ReadLine());
            Console.WriteLine("Enter the Interest Rate:");
            var interestRate = Convert.ToDouble(Console.ReadLine()) / 100;
            Console.WriteLine("Enter the Loan Years:");
            var years = Convert.ToDouble(Console.ReadLine());
            Console.WriteLine("Number of Times interest will be compound:");
            var annualCompound = Convert.ToDouble(Console.ReadLine());
            for (var i = 1; i < years + 1; i++)
            {
                var totalPayment = amount * Math.Pow(1 + interestRate / annualCompound,
                                annualCompound * i);
                Console.WriteLine($"Total for Year {i} is {totalPayment}.");
            }
            Console.ReadLine();
        }
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *