(Compound Interest Calculation) Modify Fig. 4.6 so it uses only integers to calculate the compound interest. [Hint: Treat all monetary amounts as numbers of pennies. Then “break” the re- sult into its dollar and cents portions by using the division and modulus operations. Insert a period.]

What will be an ideal response?


```
// Calculate compound interest using only integers.
#include
#include // parameterized stream manipulators
#include
using namespace std;
int main()
{
int amount; // amount on deposit, in pennies
int principal = 100000; // starting principal, in pennies ($1000)
int dollars; // dollar portion of amount
int cents; // cents portion of amount
double rate = .05; // interest rate

// display headers for table
cout << "Year" << setw( 24 ) << "Amount on deposit\n";

// loop 10 times
for ( int year = 1; year <= 10; year++ )
{
// determine new amount (in pennies)
amount = principal * pow( 1.0 + rate, year );

// determine cents portion of amount (last two digits)
cents = amount % 100;

// determine dollars portion of amount
// integer division truncates decimal places
dollars = amount / 100;

// display year, dollar portion followed by period
cout << setw( 4 ) << year << setw( 20 ) << dollars << '.';

// display cents portion
// if cents portion only 1 digit, insert 0
if ( cents < 10 )
cout << '0' << cents << endl;
else // else, display cents portion
cout << cents << endl;
} // end for
} // end main
```

Computer Science & Information Technology

You might also like to view...

A(n) ________ describes all the possible values and likelihoods that a given variable can be within a specific range, and they can be in the form of a graph, table, or formula

A) continuous variable B) probability distribution C) observational unit D) discrete variable

Computer Science & Information Technology

The connection between Zacharias Moussaoui's Internet access in Malaysia, his access from a computer lab at the University of Oklahoma, and from Kinko's came from connection logs linked to a Hotmail ________ address

Fill in the blank(s) with the appropriate word(s).

Computer Science & Information Technology

The On _____ event occurs when focus moves from one record to another.

Fill in the blank(s) with the appropriate word(s).

Computer Science & Information Technology

Unplanned exceptions that occur during a program's execution are also called execution exceptions.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology