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: 3769923 • 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 ()

{

   FILE *Balancedata;
FILE *Balanceout;
  
     
   int num_years, i;
    float ror, interest_earned, total, investment, arr[10], oldBal, newBal, retAccWithoutYC[50], retAccWithYC[50], Balance[3], Bal;
  
     

  
    {
printf("Enter the initial investment: $");
fflush(stdin);
   scanf("%f", &arr[0]);

   

   printf(" Please enter the number of years left to retire ");
   fflush(stdin);
   scanf("%d", &num_years);
  
              
   printf(" Please enter the assumed rate of return on the investment ");
fflush(stdin);
   scanf("%f", &ror);
printf(" Enter the initial value again just to make sure ");
   scanf("%f", &investment);
     

   if (arr[0] < 0 or arr[0] > 5500)
{
    printf("ERROR 1: Value must be greater than 0 and less than 5500 ");
   }
     
   else if (num_years< 1 or num_years>50)
   {
    printf("ERROR 2: Number of years must be between 1 and 50 ");
   }
   else if (ror<-15 or ror>15)
   {
    printf("ERROR 3: Assumed rate of return must be between -15 and 15 ");
   }
   else
   {
interest_earned=(float)(investment*ror*num_years)/100;
   investment=arr[0];
   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);

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]);
}

}

Balancedata = fopen("c:\Balance\FinalExam.txt", "r");
Balancedata = fopen("c:\Balance\FinalExam.txt", "w");
do
{
    fscanf(Balancedata, "%f,%f,%f", &Balance[0], &Balance[1], Balance[2]);
   
   
    for (i = 0; i<=2; i++)
    {
   Bal=Bal + Balance[i];
   }
   fprintf(Balanceout, "%f %f %f (BAL =) %f ", Balance[0],Balance[1], Balance[2], Bal);
   }



   while (!feof(Balancedata));
  
   printf("Done !");
}

Why won't my external data file open?




Explanation / Answer

#include <stdio.h>
int main ()
{
FILE *Balancedata;
FILE *Balanceout;
  

int num_years, i;
float ror, interest_earned, total, investment, arr[10], oldBal, newBal, retAccWithoutYC[50], retAccWithYC[50], Balance[3], Bal;
  
{
  
  
printf("Enter the initial investment: $");
fflush(stdin);
scanf("%f", &arr[0]);


printf(" Please enter the number of years left to retire ");
fflush(stdin);
scanf("%d", &num_years);
  
  
printf(" Please enter the assumed rate of return on the investment ");
fflush(stdin);
scanf("%f", &ror);
printf(" Enter the initial value again just to make sure ");
scanf("%f", &investment);


if ( arr[0] < 0 || arr[0] > 5500)
{
printf("ERROR 1: Value must be greater than 0 and less than 5500 ");
}

else if (num_years< 1 || num_years>50)
{
printf("ERROR 2: Number of years must be between 1 and 50 ");
}
else if (ror<-15 || ror>15)
{
printf("ERROR 3: Assumed rate of return must be between -15 and 15 ");
}
else
{
interest_earned=(float)(investment*ror*num_years)/100;
investment=arr[0];
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);
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]);
}

}

Balancedata = fopen("FinalExam.txt", "r");
Balanceout=fopen("FinalExam2.txt","w+");
  
do
{
fscanf(Balancedata, "%f,%f,%f", &Balance[0], &Balance[1], &Balance[2]);

  
for (i = 0; i<=2; i++)
{
Bal=Bal + Balance[i];
}
fprintf(Balanceout, "%f %f %f (BAL =) %f ", Balance[0],Balance[1], Balance[2], Bal);
}
  
while (!feof(Balancedata));
  
printf("Done !");
}

/*this one is working, i have named output file as FinalExam2.txt and input as FinalExam.txt, there was problem in making filepointers in your code*/

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