(Compound Interest) Modify the compound interest program of Section 4.4 to repeat its steps for the interest rates 5%, 6%, 7%, 8%, 9% and 10%. Use a for statement to vary the interest rate.

What will be an ideal response?

```
// Calculating compound interest with several interest rates.
#include
#include // parameterized stream manipulators
#include // math functions
using namespace std;

int main()
{
double amount; // amount on deposit
double principal = 1000.0; // starting principal

// set floating-point number format
cout << fixed << setprecision( 2 );

// loop through interest rates 5% to 10%
for ( int rate = 5; rate <= 10; rate++ )
{
// display table headers
cout << "Interest Rate: " << rate << "%"
<< "\nYear\tAmount on deposit\n";

// calculate amount on deposit for each of ten years
for ( int year = 1; year <= 10; year++ )
{
// calculate new amount for specified year
amount = principal * pow( 1 + ( rate / 100.0 ), year );
// output one table row
cout << year << '\t' << amount << '\n';
} // end for

cout << '\n';
} // end for

cout << endl;
} // end main
```

Computer Science & Information Technology

You might also like to view...

A(n) ________ is larger than a terabyte

Fill in the blank(s) with correct word

Computer Science & Information Technology

________ refers to the placement of text or objects relative to the left and right margins

Fill in the blank(s) with correct word

Computer Science & Information Technology