Q:

C# program to calculate the compound interest

belongs to collection: C# Basic Programs | basics

0

C# program to calculate the compound interest

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program:

The source code to calculate the compound interest is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.

//C# program to calculate the compound interest. 

using System;

class Interest
{
    static void CalculateCompoundInterest(double amount, double roi, int years, int annualCompound)
    {
        double result = 0;
        int loop = 0;

        for (loop = 1; loop <= years; loop++)
        {
            result = amount * Math.Pow((1 + roi / annualCompound), (annualCompound * loop));
            Console.WriteLine("Your amount after {0} Year " + ": {1}", loop, result);
        }

    }
    private static void Main()
    {
        int years          = 0;
        int annualCompound = 0;

        double roi         = 0;
        double amount      = 0;
        
        Console.Write("Enter the amount : ");
        amount = double.Parse(Console.ReadLine());
        
        Console.Write("Enter the rate of interest : ");
        roi = double.Parse(Console.ReadLine()) / 100;
        
        Console.Write("Enter the total number of years : ");
        years = int.Parse(Console.ReadLine());
        
        Console.Write("Compounding frequency : ");
        annualCompound = int.Parse(Console.ReadLine());
        
        CalculateCompoundInterest(amount, roi, years, annualCompound);
    }
}

Output:

Enter the amount : 2500
Enter the rate of interest : 7.5
Enter the total number of years : 2
Compounding frequency : 2
Your amount after 1 Year : 2691.015625
Your amount after 2 Year : 2896.62603759766
Press any key to continue . . .

Explanation:

Here, we create a class Interest that contains two static methods CalculateCompoundInterest() and Main(). The CalculateCompoundInterest() method calculates the compound interest according to the standard calculation method and prints the amount year wise on the console screen.

The Main() method is the entry point for the program, here we read the values from the user and passed to the CacluateCompoundInterest() method and print the amount year wise.

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C# Basic Programs | basics

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C# program to calculate the Cosine(X) using a pred... >>
<< C# program to calculate the Standard Deviation of ...