Calculating Interest – C++

What it does:

Calculates the interest of a balance of 5 years. The interest is set a .05 initially and the bank balance is set at 1000. Prints out in a table with two headers for the year and amount.


#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

int main()
    double amount;
    double initalAmount = 1000.0;
    double rate = .05;
    cout << "Year" << setw(21) << "Amount on deposit" << endl;
    //setting floating point num
    cout << fixed << setprecision(2);
    //caculating the amount for 5 years
    for(int year=1; year<=5; year++)
        //caculating the amount for specified year
        amount = initalAmount * pow(1.0 + rate, year);
        //displaying the amount + year
        cout << setw(4) << year << setw(21) << amount << endl;
    return 0;

2 thoughts on “Calculating Interest – C++

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s