Compound Interest

Earl and Larry each begin full-time
jobs in January 2015 and plan to retire in January 2063 after working for
48 years. Assume that any money they deposit into IRAs earns 4%
interest compounded annually. Earl opens a traditional IRA account
immediately and deposits $5,000 into his account at the end of each year
for fifteen years. After that he plans to make no further deposits and just
let the money earn interest. Larry plans to wait fifteen years before
opening his traditional IRA and then deposit $5,000 into the account at
the end of each year until he retires. Write a program that calculates the
amount of money each person has deposited into his account and the
amount of money in each account upon retirement.

can someone just help me figure out the math here? i know we have to use this formula: A = P (1 + r/n)^(nt)

thank you for any tips

#include <cmath>

z = pow(x,y); //x to the y power

the rest of it is standard c++ math.

so that looks like,

a = p* pow( (1.0 + r/n), n*t)
I think. Power first, then multiply by P at the end, right?


Assume that any money they deposit into IRAs earns 4%
interest
compounded annually.

Earl opens a traditional IRA account
immediately and deposits $5,000 into his account at the end of each year
for fifteen years. After that he plans to make no further deposits and just
let the money earn interest.

I've bolded the parts of importance in this question.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
const int earl_yrs = 15;
const double int_rate = 0.04, earl_deposit = 5000;

double earl_total = 0.0;
// do this every year for earl_yrs years
for( int i = 0; i < earl_yrs; i++ ) {
    // deposit money
    earl_total += earl_deposit;
    // add on interest
    earl_total *= 1 + int_rate;

    // print out current balance
    std::cout << "after year " << i + 1 << ", earl has $" << std::fixed << std::setprecision( 2 ) << earl_total << '\n';
}
Topic archived. No new replies allowed.