Q 5.14 (Modified Compound-Interest Program) Modify the compound-interest application of Fig. 5.6 to repeat its steps for
interest rates of 5%, 6%, 7%, 8%, 9% and 10%. Use a for loop to vary the interest rate.
#include < iostream>
using std: : cout;
using std: : endl;
using std: : fixed;
#include < iomanip>
using std: : setw; // enables program to set a field width
using std: : setprecision;
#include < cmath> // standard C++ math library
using std: : pow; // enables program to use function pow
int main()
{
double amount; // amount on deposit at end of each year
double principal;
// display headers
cout << setw( 4 ) << "Year" << setw( 9 ) << "Dep. (%X) " <<endl;
// set floating‐point number format
cout << fixed << setprecision( 2 ) ;
for( int rate = 5; rate <= 10; rate++) {
principal = 1000. 0;
// calculate amount on deposit for each of ten years
for ( int year = 1; year <= 10; year++)
{
principal = principal * pow( 1 + rate/100. 0, year ) ;
cout << setw( 4 ) << year << setw( 9 ) << principal << endl;
}
cout << endl;
}/
/ end for
system("pause") ;
return 0; // indicate successful termination
} // end main