You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
1.2 KiB
C#

/*
* 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