Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

c program calculations will need to be done once a vear for the length of the te

ID: 3714481 • Letter: C

Question

c program

calculations will need to be done once a vear for the length of the term CThat means (f the term is 5 yoars this calculation willbe done 5 time for each array ) Each vearly calculation will be put in an array element 4 Points) Open up an external data file that will be used to generate a report 2 Points) The first line of the report should state what the assumed interest rate is and how many years are being simulated. (You can add extra information if you wish, such as a person's name or the date the report was generated) (8 Points) The rest of the report will be the data from the two arrays. Each line will state the year (starting at year O when the initial contribution was deposited), the balance if there was only an initial contribution, and the balance if there were yearly contributions If your initial contribution was $5000 and the interest rate is 8 (representing 8%) then the output file might look like this Simulation with a $5000 contribution with 8% growth Year 0 (no yearly contributions) $5000 00 (with yearly contributions) 5000 00 Year 1 (no yearly contributions) $5400.00 (with yearly contributions) $10400.00 Year 2 (no yearly contributions) $5832 0o with yearly contributions) $16232.00 Year 3 (no yearly contributions) $6298.56 (with yearly contributions) s22530.56 Year 4 (no yearly contributions) S6802.44 (with yearly contributions) $29333.00 Year 5 (no yearly contributions) $7346.64 (with yearly contributions) $36679 65 C3 EC Points) Create a third array to demonstrate how much more money will be in the investment account if there are yearly contributions. This is simply the difference between the previous two arrays. Simulation with a $5000 contribution with 8% growth Year 0 (no yearly contributions) $5000.00 (with yearly contributions) $5000.00 (difference) $0.00 Year 1 (no yearly contributions) $5400.00 (with yearly contributions) $10400.00 (difference) $5000.00 Year 2 (no yearly contributions) $5832.00 (with yearly contributions) $16232.00 (difference) $10400.00 Year 3 (no yearly contributions) $6298.56 (with yearly contributions) $22530.56 (difference) $16232.00 Year4 (no yearly contributions) $6802.44 (with yearly contributions) $29333.00 (difference) $22530.56 Year 5 (no yearly contributions) $7346.64 (with yearly contributions) $36679.65 (difference) $29333.00

Explanation / Answer

The C code is as follows :

// NAME -
// DATE -

#include <stdio.h>
#include<math.h>
#include<stdbool.h>
int main()
{
float array1[50]; // declaring the float arrays
float array2[50];
bool valid; // bool variable to check if input is valid
float initial_investment;
int age_till_retirement;
float rate_of_return;
do
{
printf("Enter a valid initial investment: must be greater than zero and less than equal to $5000 ");
scanf("%f", &initial_investment); // taking input
if(initial_investment > 0 && initial_investment <= 5000) // checking if it is valid
{
valid = true; // if valid
}
else
{
valid = false; //if not valid
}
}while(valid == false); // loop will repeat if not valid until valid value is inputted

array1[0] = initial_investment; // storing the investment at element zero of one array
do
{
printf("Enter a valid number of years till retirement, must be between 1 and 50 ");
scanf("%d", &age_till_retirement); // taking the input
if(age_till_retirement >= 1 && age_till_retirement <= 50) // checking if it is valid
{
valid = true; // if valid
}
else
{
valid = false; // if not valid
}
}while(valid == false); // will loop again if not valid

do
{
printf("Enter a valid assumed rate of return, must be between 15 and -15 ");

scanf("%f", &rate_of_return); // taking input
if(rate_of_return >= -15 && rate_of_return <= 15) // checking if the input is valid
{
valid = true; // if valid
}
else
{
valid = false; // if not valid
}
}while(valid == false); // will loop again if not valid

array2[0] = array1[0]; // storing the element zero of one array in another

int i;
float OldBalance = array2[0]; // old balance will be the initial investment
float NewBalance;
for(i = 1; i <= age_till_retirement; i++) // to loop for given number of years
{
NewBalance = OldBalance * (1 + (rate_of_return/100.0)); // calculating the new balance every year
OldBalance = NewBalance; // each year the new balance will be the old balance for the next year
}

printf("The balance at the end of the retirement will be $%f ", NewBalance); // printing the output
return 0;

}

Output :

Enter a valid initial investment: must be greater than zero and less than equal to $5000
6000
Enter a valid initial investment: must be greater than zero and less than equal to $5000
4500
Enter a valid number of years till retirement, must be between 1 and 50
55
Enter a valid number of years till retirement, must be between 1 and 50
45
Enter a valid assumed rate of return, must be between 15 and -15
-16
Enter a valid assumed rate of return, must be between 15 and -15
13
The balance at the end of the retirement will be $1100886.125000

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote