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)
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
constint earl_yrs = 15;
constdouble 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';
}