Need help on calculating compound interest in the C# Course

My code:

Console.WriteLine("This program will calculate compound interest");
Console.Write("Enter Principal investment amount: ");
int P = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter annual interest rate: ");
int r = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter the number of times that interest is compounded: ");
int n = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter the time the money is invested or borrowed for: ");
int t = Convert.ToInt32(Console.ReadLine());

double compoundInterest = Math.Pow((r/n + 1), (n * t));
compoundInterest = compoundInterest * P;

Console.WriteLine("The calculated compound interest is: " + compoundInterest);

Hello @cricke6353535163, welcome to the forums! What exactly do you need help with? Can you be more specific. For example, if there is an error message, what is it? If there’s a logical error, what is it, and how does the output differ from the expected output?

The Annual Interest Rate is a Decimal. So instead of using the Convert.ToInt32(), I used Convert.ToDouble() and assign it to a “double”, otherwise you will get an error in Type Conversion when you enter say “0.05” for example.