Author : Rahul

Write a program to calculate compound interest


Program

using System;

namespace ProgrammingQuestion
{
 class Program
 {
   static void Main(string[] args)
   {
     //Variable Declaration
     string principleVal, rateVal, timeVal;
     double principle, rate, compoundInterest, amount;
     int time;
     
     //User Input
     Console.Write("Enter Principle:");
     principleVal = Console.ReadLine();
     principle = Convert.ToDouble(principleVal);
     Console.Write("Enter Rate:");
     rateVal = Console.ReadLine();
     rate = Convert.ToDouble(rateVal);
     Console.Write("Enter Year:");
     timeVal = Console.ReadLine();
     time = Convert.ToInt32(timeVal);
     
     //Compound Interest Logic
     amount = principle * Math.Pow((1+(float)(rate/100)), time);
     compoundInterest = amount - principle;
     
     //Print Result
     Console.WriteLine($"Compound Interest: {compoundInterest}");
     Console.WriteLine($"Total Amount: {amount}");
     Console.Read();
   }
 }
}

Output

Enter Principle:10000
Enter Rate:9.5
Enter Year:3
Compound Interest: 3129.32370711953
Total Amount: 13129.3237071195