# Thread: help with compounded interest

1. ## help with compounded interest

The code below was supposed to display interest yearly like:
Year 1 \$1000
Year 2 \$1100
Year 3 \$1210

Problem is it will display the value for the last year for all 3 years... what am i doing wrong?

Code:
```#include <iostream>
#include <cmath>
using namespace std;

int main()
{

//Declare variables
double percent_return = 0;
double investment = 0;
int nYears = 0;
double value = 0;
int count = 0;

cout << "Enter the initial amount of the investment: " << endl;
cin >> investment;

cout << "Enter the interest rate: " << endl;
cin >> percent_return;

//Ask user for number of years
cout << "Enter the number of years: " << endl;
cin >> nYears;

for(count = 1; count <= nYears; count++)
{

value = investment * pow(1 + percent_return, nYears);

cout << value << endl;

}

return 0;

}```

3. Sorry.

4. Code:
`value = investment * pow(1 + percent_return, nYears);`
The problem is on that line
investment never changes
percent_return never either
neither does nYears
Well, something got to change during the iteration of the loop. What would that be?
Welcome to the board

5. i don't want nYears to be constant....

6. Code:
`value = investment * pow(1 + percent_return, count);`

7. ah, okay.... makes sense. thanks