Answer to Question #340698 in C++ for Lwandiso

Question #340698

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%.


1
Expert's answer
2022-05-13T17:01:37-0400
#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;
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS