c programming You have been contrac ted to write a program for an investment hou
ID: 3720148 • Letter: C
Question
c programming
You have been contrac ted to write a program for an investment house They want to use th program to try and get people to invest for retirement This program will calculate the earnings on a Roth Individual Retirement Account (IRA) A Roth IRA (named after the Se nator who proposed this retirement plan) lets you deposit after ta earned inc ome in investment accounts If you use the money for retirement after age then all the earnings you made from the investments are tax free (normally these earnings would be subjected to capital gains tax). Your program will be running two simulations and storing the answers in two different float arrays 2.Peints) Comment the top of your code with your name and the date. Make all of your variable names meaningful and easy to understand 2 Points) Make sure your code is neat (braces tabbed in and lined up) 2 Points) Read the initial investment for your Roth IRA and store it in element zero of the array. This investment value must be greater than $0 (obviously) and less than or equal to $5500 (the current maximum yearly limit) 2 Points) Read in an integer representing the number of years until retirement. This value represents how many years will pass before you are going to use the money and this is called the TERM. The term value should be between 1 and 50 (2 Points) Read in an assumed rate of return. This is a value that will represent how much the investment will increase (or decrease) each year. This value will be a float value that will be between -15 and 15. In reality, this number would change each year but to keep the program simple we are going to assume this value is fixed for the ternm (length) of the investment 4 Points) Do not do any calculations if any of the previous three values are invalid C2 EC Points) If the user enters a value that is less than $O or greater than $5500 have the program warn the user of the limits and ask them to re-enter the starting value. The program should not advance until a valid value is entered. This same logic should be used for the rate of retum and the number of years. (2 Point) Once a valid value has been entered into element zero of the float array, copy the starting value into element zero of a second float array 10 Points) Use one of the arrays to figure out how much the retirement account would be worth each year if the investor put money in the account once and never again. The equation to calculate the yearly balance with no yearly contribution is NewBalance OldBalance (1 (InterestRate /100.0)Explanation / Answer
Please add your name and date on the top of the code. It also includes the code for bonus question( *3EC).
Appropriate comments are included and variable names are pretty expressive.
-- code starts from below --
#include <stdio.h>
/*
Name : Your name
Date : Write date here
*/
int main(){
int term;
int invalid = 0; // To check invalid input
do{
if(invalid)
printf("Term must be between 1 to 50 ");
printf("Enter term (Number of years until retirement): ");
scanf("%d", &term);
if(term < 1 || term > 50)
invalid = 1;
else
invalid = 0;
}
while( term < 1 || term > 50);
term++;
float retirement_wo_yearly_contribution[term], retirement_w_yearly_contribution[term];
do{
if(invalid)
printf("Initial investment must be greater than 0 and less than or equal to 5500 ");
printf("Enter initial investment :");
scanf("%f", &retirement_wo_yearly_contribution[0]);
if(retirement_wo_yearly_contribution[0] <= 0 || retirement_wo_yearly_contribution[0] > 5500)
invalid = 1;
else
invalid = 0;
}
while(retirement_wo_yearly_contribution[0] <= 0 || retirement_wo_yearly_contribution[0] > 5500);
float yearly_contribution = retirement_wo_yearly_contribution[0];
float rate_of_return;
do{
if(invalid)
printf("Assuemd rate of return must be between -15 and 15 ");
printf("Enter assumed rate of return: ");
scanf("%f", &rate_of_return);
if(rate_of_return < -15 || rate_of_return > 15)
invalid = 1;
else
invalid = 0;
}
while(rate_of_return < -15 || rate_of_return > 15);
retirement_w_yearly_contribution[0] = retirement_wo_yearly_contribution[0];
for(int i = 1; i < term; i++)
{ // calculation
retirement_wo_yearly_contribution[i] = retirement_wo_yearly_contribution[i-1]*( 1 + (rate_of_return/100.0));
retirement_w_yearly_contribution[i] = retirement_w_yearly_contribution[i-1]*( 1 + (rate_of_return/100.0)) + yearly_contribution;
}
FILE *fp;
fp = fopen("report.txt", "w");
fprintf(fp, "Simulation with a $%.2f contribution with %2.2f%% growth ", yearly_contribution, rate_of_return);
for(int i = 0; i < term; i++)
{
fprintf(fp, "Year %d (no yearly contributions) $%.2f (with yearly contributions) $%.2f (difference) $%.2f ", i, retirement_wo_yearly_contribution[i], retirement_w_yearly_contribution[i], retirement_w_yearly_contribution[i] - retirement_wo_yearly_contribution[i]);
}
fclose(fp);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.