I am new to C++ programming, but I am trying to modify the following code so that I can calculate compound interest using only integers. I only clues I have are to (Treat all monetary amounts as integral numbers of pennies. Then "break" the result into its dollar portion and cents portion by using the division and modulus operations. Insert a period.) If anyone could help me along in the right direction or help me find resources that explain this I would greatly appreciate it. Thanks.
#include <iostream>
using std::cout;
using std::endl;
using std::ios;
#include <iomanip>
using std::setw;
using std::setiosflags;
using std::setprecision;
#include <cmath>
int main()
{
double amount, // amount on deposit
principal = 1000.0, // starting principal
rate = .05; // interest rate
cout << "Year" << setw( 21 )
<< "Amount on deposit" << endl;
// set the floating-point number format
cout << setiosflags( ios::fixed | ios::showpoint )
<< setprecision( 2 );
for ( int year = 1; year <= 10; year++ ) {
amount = principal * pow( 1.0 + rate, year );
cout << setw( 4 ) << year << setw( 21 ) << amount << endl;
}
return 0;
}