Calculate compound interest with a principal of $24.00 and - C++ Data Type

C++ examples for Data Type:double

Description

Calculate compound interest with a principal of $24.00 and

Demo Code

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

int main(int argc, const char *argv[]) {
    double amount;
    double principal = 24.0f;

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

    for (float rate = 0.05; rate <= 0.10; rate += 0.01) {
        std::cout << "\nInterest rate: " << rate * 100 << "%\n" << "Year" << std::setw(30) << "Amount on deposit" << std::endl;
        for (int year = 1626; year < 2020; year++) {
            amount = principal * pow(1.0 + rate, year - 1626);
            if (year == 2020) {
                std::cout << std::setw(4) << year << std::setw(30) << amount << std::endl;
            }/*from  w w w .  j a  v a  2s .c o  m*/
        }
    }
    return 0;
}

Result


Related Tutorials