Click here to Skip to main content
15,908,175 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I've written a C# program to calculate the total of the money invested at different amounts of interest rates.

Compound interest formula I'm using: P (1 + r )n

I cant see what I'm doing wrong.

For example:
Amount: 100
Rate: 10
years: 5
With a calculator the answer is 161.05

But once I do it with my program it calculates to 100.00001

Your help is much appreciated.

What I have tried:

double amount;
     double rate;
     double years;
     double total;
     amount = Convert.ToDouble(textBox1.Text);
     rate = Convert.ToDouble(textBox2.Text);
     years = Convert.ToDouble(textBox3.Text);

     rate = rate / 100;

     total = amount * 1 + Math.Pow(rate, years);

     label1.Text = total.ToString();
Posted
Updated 21-Jun-18 10:18am

1 solution

You didn't traslate correctly the formula.
Quote:
total = amount * 1 + Math.Pow(rate, years);
Should be instead
total = amount * Math.Pow(1 + rate, years);
 
Share this answer
 
Comments
Member 13652359 21-Jun-18 16:55pm    
...Such a small error.
Thanks, CPallini
CPallini 21-Jun-18 16:56pm    
You are welcome.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900