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

I need help adding on to my C program. it can\'t be C+, has to be regular C. Thi

ID: 3769171 • Letter: I

Question

I need help adding on to my C program. it can't be C+, has to be regular C. This is what I have so far:

#include<stdio.h>

main ()

{

int num_years;

float ror, interest_earned, total, investment;

double arr[10];

while(1)

{

printf("Enter the initial investment: $");

scanf("%lf", &arr[0]);

if(arr[0] > 0 && arr[0] <= 5000) break;

else printf("Amount not in range ");

}

printf(" Please enter the number of years left to retire ");

fflush(stdin);

scanf("%d",&num_years);

if(num_years<1||num_years>50)

{

printf("Enter value between 1 and 50");

scanf("%d",&num_years);

}

printf(" Please enter the assumed rate of return on the investment ");

scanf("%f",&ror);

if(ror<-15 || ror>15)

{

printf("Enter value between -15 and 15");

scanf("%f",&ror);

}

investment = arr[0];

interest_earned=(float)(investment*ror*num_years)/100;

printf("The interest on your investment %f is %f ",investment, interest_earned);

total=investment+interest_earned;

printf("You will recieve the amount %f at the time of retirement ",total);

}

I need to 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: NewBalcace=OldBalance*(1+(InterestRate/100.0))

Then I need to use the second array to figure out how much the retirement would be worth each year if the investor deposited the same amount of money in the account every year(assume the first deposit is the same as the yearly contribution). The equation to calculate the yearly balance with a yearly contribution is:

NewBalance=OldBalance* (1+InterestRate/100.0)) + YearlyContribution.

These calculations will need to be done once a year for the length of the term.(so if the term is 5 years, the calculation will be done 5 times for each array.) Each yearly calculation will be put in an array element.

Explanation / Answer

I have made the required changes to the C code. It now calculates the retirement account balance every year for both with and without yearly contributions.

#include<stdio.h>

void main ()

{

   int num_years;
   float ror, interest_earned, total, investment;
   double arr[10];
  
   double *retAccWithoutYC; // Without yearly contribution
   double *retAccWithYC;      // With yearly contribution

   double oldBal, newBal;
   int i;

   while(1)
   {
       printf("Enter the initial investment: $");
       scanf("%lf", &arr[0]);
       if(arr[0] > 0 && arr[0] <= 5000) break;
       else printf("Amount not in range ");
   }

   printf(" Please enter the number of years left to retire ");
   fflush(stdin);
   scanf("%d",&num_years);
   if(num_years<1||num_years>50)
   {
       printf("Enter value between 1 and 50");
       scanf("%d",&num_years);
   }

   printf(" Please enter the assumed rate of return on the investment ");
   scanf("%f",&ror);
   if(ror<-15 || ror>15)
   {
       printf("Enter value between -15 and 15");
       scanf("%f",&ror);  
   }

   investment = arr[0];

   interest_earned=(float)(investment*ror*num_years)/100;
   printf("The interest on your investment %f is %f ",investment, interest_earned);

   total=investment+interest_earned;
   printf("You will recieve the amount %f at the time of retirement ",total);

  
   retAccWithoutYC = (double*)malloc((num_years+1) * sizeof(double));
   retAccWithYC = (double*)malloc((num_years+1) * sizeof(double));

   oldBal = investment;
   retAccWithoutYC[0] = investment;
   retAccWithYC[0] = investment;

   for(i=1; i<num_years+1; i++)
   {
       newBal = oldBal * (1 + (ror/100));
       retAccWithoutYC[i] = newBal;
       oldBal = newBal;
   }

   oldBal = investment;
   for(i=1; i<num_years+1; i++)
   {
       newBal = oldBal * (1 + (ror/100)) + investment;
       retAccWithYC[i] = newBal;
       oldBal = newBal;
   }

   printf(" Yearly Contribution: %10.2f", investment);

   printf(" Balance in the Retirement Account every year with and without yearly contribution");
   printf(" %-10s%-15s%-15s ", "In Year", "Bal w/o YC", "Bal with YC");
      
   for(i=0; i<num_years; i++)
   {
       printf("%-10d%-15.2f%-15.2f ", i+1, retAccWithoutYC[i], retAccWithYC[i]);
    }
}

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