Using the following formula a = p ( 1 + r ) n .write a program that calculates and prints the amount of money in the account at the end of each year for 10 years. the program should use interest rate of 5%, 6%, 7%, 8%, 9%, 10%.
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
double amount; // amount on deposit at end of each year
double principal;// amount before interest
double rate;// annual interest rate
for(unsigned int i = 5; i <= 10; ++i )
{
principal = 1000.0;
rate = .01;
cout << "Year" << setw( 25 )<< "Amount on deposit (" << i << "%)" << endl << endl;
// set floating-point number format
cout << fixed << setprecision( 2 );
rate *= i;
// calculate amount on deposit
for (unsigned int year = 1; year <= 10; ++year )
{
amount = principal * pow( 1.0 + rate, year );
cout << setw( 4 ) << year << setw( 28 ) << amount << endl;
}
cout << endl;
}
}
Comments
Leave a comment