Compound Interest, varying rates

I am totally confused on how to write the formula for a compound interest. I thought that it would be A = P (1+r/n)^n+t, but the rates vary between each performance year and I wasn't taught how to do that in code. Please help.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include        <iostream>
#include        <math.h>
using namespace std;

int main(void)

{
        double  Principal;
        double  Perf1;
        double  Perf2;
        double  Perf3;
        double  Perf4;
        double  FinVal;

        cout.setf(ios::showpoint);
        cout.setf(ios::fixed);
        cout.precision(2);

        cout << "Please enter the initial amount invested: $ ";
        cin >> Principal;
        cout << "Please enter the performance for year #1: % ";
        cin >> Perf1;
        cout << "Please enter the performance for year #2: % ";
        cin >> Perf2;
        cout << "Please enter the performance for year #3: % ";
        cin >> Perf3;
        cout << "Please enter the performance for year #4: % ";
        cin >> Perf4;

        FinVal = (1+ Perf4/1)^4;

        cout << "The final value of the stock is: $ " << FinVal << endl << endl;
        return 0;
}
Registered users can post here. Sign in or register to post.