Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem Statement A 401(k) plan is a type of tax-qualified account for people to save for retirement. Employees typically have part of their pre-tax pay

Problem Statement

A 401(k) plan is a type of tax-qualified account for people to save for retirement. Employees typically have part of their pre-tax pay check deposited into such an account and employers may match a certain amount of those contributions. As of 2018, there was a maximum annual contribution limit of $18,500.

The money contributed to a 401(k) account may be invested in many different ways. While the account may grow tax free, it is not immune to inflation. To account for inflation, you can use the following formula which is the inflation-adjusted rate of return.

inflation-adjusted rate of return = ((1 + rate of return)/(1 + inflation rate)) 1

Write a program that produces an amortization table for a 401(k) account. Your program will read the following inputs as command line arguments:

  • An initial starting balance
  • A monthly contribution amount (well assume its the same over the life of the savings plan)
  • An (average) annual rate of return (on the scale [0, 1])
  • An (average) annual rate of inflation (on the scale [0, 1])
  • A number of years until retirement

Your program will then compute a monthly savings table detailing the (inflation-adjusted) interest earned each month, contribution, and new balance. To get the monthly rate, simply divide by 12. Each month, interest is applied to the balance at this rate (prior to the monthly deposit) and the monthly contribution is added. Thus, the earnings compound month to month. Be sure to round appropriately, to the nearest cent so that rounding errors do not compound.

Your program will need to validate the input and quit with an error message on any potential bad input(s). For inputs

10000 500 0.09 0.012 10 

your output should look something like the following:

Month Interest Balance 1 $ 64.23 $ 10564.23 2 $ 67.85 $ 11132.08 3 $ 71.50 $ 11703.58 4 $ 75.17 $ 12278.75 5 $ 78.87 $ 12857.62 6 $ 82.58 $ 13440.20 7 $ 86.33 $ 14026.53 8 $ 90.09 $ 14616.62 9 $ 93.88 $ 15210.50 ... 116 $ 678.19 $ 106767.24 117 $ 685.76 $ 107953.00 118 $ 693.37 $ 109146.37 119 $ 701.04 $ 110347.41 120 $ 708.75 $ 111556.16 Total Interest Earned: $ 41556.16 Total Nest Egg: $ 111556.16

I was able to create a loop but I wasn't able to get the Total Interest Earned and I couldn't figure out how to round the balance to the nearest cent.

Here is my code:

#include #include #include

int main(int argc, char **argv) { double balance; double monthlyContribution; double returnRate; double inflationRate; double inflaReturnRate; int yearsUntilRetired; int months; scanf ("%lf %lf %lf %lf %d", &balance, &monthlyContribution, &returnRate, &inflationRate, &yearsUntilRetired); if ((returnRate > 1) || (returnRate < 0) || (inflationRate > 1) || (inflationRate < 0)) { printf ("Invalid input "); } months = yearsUntilRetired * 12; inflaReturnRate = ((returnRate + 1) / (inflationRate + 1)) - 1; printf ("Month Interest Balance "); int i; for (i = 1; i <= months; i++) { returnRate = (inflaReturnRate * balance) / 12; balance = balance + returnRate + monthlyContribution; printf ("%d $ %0.2f $ %0.2f ", i, returnRate, balance); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Explain how CSMA/CA DCF works.

Answered: 1 week ago