Compound interest calculations with for. - C++ Statement

C++ examples for Statement:for

Description

Compound interest calculations with for.

Demo Code

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

int main(int argc, const char *argv[]) {
    double amount;
    double principal = 1000.0f;
    double rate = .05f;

    std::cout << "Year" << std::setw(21) << "Amount on deposit" << std::endl;

    std::cout << std::fixed << std::setprecision(2);

    for (int year = 0; year <= 10; ++year) {
        amount = principal * pow(1.0f + rate, year);

        std::cout << std::setw(4) << year << std::setw(21) << amount
                  << std::endl;/*from   w  ww.j a v a 2  s  .c o  m*/
    }
    return 0;
}

Result


Related Tutorials