
Patrick B. answered 09/28/19
Math and computer tutor/teacher
Use the formula P*(1+r)^t where P=1000 r = 0.05 and t=10
the 16288.94 figure is correct !!!
You only need one for loop!!!!
If you must display in annually in a table then here is some code:
using namespace std;
#include <iostream>
#include <iomanip>
#include <math.h>
int main()
{
double newPrincipal;
double P;
double rate = 0.05;
double interestEarned;
double Principal=10000;
int t=10;
P = Principal;
cout << "Year Starting Principal interest Earned new Principal " << endl;
for (int iLoop=1; iLoop<=t; iLoop++)
{
interestEarned = Principal*rate;
newPrincipal = Principal + interestEarned;
//pardon the white space; otherwise use std::setwidth()
cout << iLoop << " " << std::setprecision(2) << std::fixed << Principal
<< " " << std::setprecision(2) << std::fixed << interestEarned
<< " " << std::setprecision(2) << std::fixed << newPrincipal << endl;
Principal = newPrincipal;
}
cout << "shortcut formula says: " << P*pow(1+rate,t) << endl;
}