programming-examples/c-sharp/Mathematics/C# Program to Calculate Compound Interest.cs

36 lines
1.2 KiB
C#
Raw Normal View History

2019-11-15 12:59:38 +01:00
/*
* C# Program to Calculate Compound Interest
*/
using System;
namespace compund
{
class compound
{
static void Main(string[] args)
{
double Total = 0, interestRate, years, annualCompound, Amount;
Console.Write("Enter the Initial Amount : ");
Amount = Convert.ToDouble(Console.ReadLine());
Console.Write("Enter the Rate of Interest : ");
interestRate = Convert.ToDouble(Console.ReadLine()) / 100;
Console.Write("Enter the 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 = Amount * Math.Pow((1 + interestRate / annualCompound), (annualCompound * t));
Console.Write("Your Total for Year {0} "
+ "is {1:F0}. \n", t, Total);
}
Console.ReadLine();
}
}
}
/*
Enter the Initial Amount : 1000
Enter the Rate of Interest : 2
Enter the Number of Years : 2
Number of Times the Interest will be Compounded : 2
Your Total for Year 1 is : 1020
Your Total for Year 2 is : 1041