Interest rates giving far off numbers than expected

I am relatively new to C++, but I was wondering why I was getting off calculations in my interest equation. I need to display the interest acquired after 5 years, displaying each individual year's income. It has been producing numbers in the ten-thousands (33632) I am entering $1000 as the principle amount. Thanks for help in advance!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
  int main () {
    double r = 1.02;
    double b = 0.0;
    double p = 0.0;
    int t = 1;
    
    cout << "Please enter the amount of money in the savings account: ";
    cin >> p;
    
    while (t <= 5) {
          b = p * pow(1 + r, t);
          cout << fixed << setprecision(2);
          cout << "After " << t << " years $" << b << " has been accumulated " << endl;
          t++;

    }
Well. Now I feel stupid. I meant to put the interest rate as 2% but instead put 102%
It has been producing numbers in the ten-thousands (33632) I am entering $1000 as the principle amount.

Which is correct for 102% interest, compounded once annually. Perhaps you meant to calculate it for 2% interest?
Topic archived. No new replies allowed.