This C# program will help you to find out compound interest for given input values.
Program to calculate compound interest:
using System;
namespace MyApp
{
class compound_interest_class
{
static void Main(string[] args)
{
double Total = 0, interestRate, years, annualCompound, inAmount;
Console.Write("Please Enter:");
Console.Write("Initial Amount: ");
inAmount = Convert.ToDouble(Console.ReadLine());
Console.Write("interest rate: ");
interestRate = Convert.ToDouble(Console.ReadLine()) / 100;
Console.Write("Number of Years: ");
years = Convert.ToDouble(Console.ReadLine());
Console.Write("Number of times the interest will be compounded: ");
annualCompound = Convert.ToDouble(Console.ReadLine());
for (int t = 1; t < years + 1; t++)
{
Total = inAmount * Math.Pow((1 + interestRate / annualCompound), (annualCompound * t));
Console.Write("Your total for year {0} "
+ "is {1:F0}. \n", t, Total);
}
Console.ReadLine();
}
}
}
No comments:
Post a Comment