Question: I'm using Xcode Version 9.4.1. How do you set my source code and account.txt both are in the same directory? because my output result was

I'm using Xcode Version 9.4.1. How do you set my source code and account.txt both are in the same directory? because my output result was "account.txt could not be opened for input.Program ended with exit code: 1" Can you explain step by step with pictures?

This is my account.txt

I 478.83 D 127.45 D 619.84 C 945.12 C 4.76 D 32.81 C 1.06 D 184.32 C 495.18 C 141.81 C 255.10 D 250.00 D 123.88 D 245.05 D 873.25 C 981.12 D 317.84 C 812.73 D 606.12

and this is my code

#include

#include

FILE *fpIn,*fpOut;

void outputHeaders(void);

void initilBalance(double amount, double *balance, double *service, double *openBalance) ;

void deposit(double amount,double *balance, double *service, int *numDeposit, double *amtDeposit);

void check(double amount,double *balance, double *service, int *numCheck, double *amtCheck);

void outputSummary(int numDeposit,double amtDeposit, int numCheck, double amtCheck, double openBalance,double service, double closeBalance);

void outputHeaders(void)

{

printf("%10s%15s%15s%15s ", "Transaction", "Deposit", "Check", "Balance");

printf("%s%15s%15s%16s ", "-----------", "-------", "-----", "--------");

fprintf(fpOut,"%10s%15s%15s%15s ", "Transaction", "Deposit", "Check", "Balance");

fprintf(fpOut,"%s%15s%15s%16s ", "-----------", "-------", "-----", "--------");

}

void initialBalance(double amount, double *balance, double *service, double *openBalance)

{

*balance = amount;

*service = 3.00;

*openBalance = amount;

fprintf(fpOut, "Initial Balance %.2lf ", *openBalance);

printf("%s%41.2lf ", "Initital Balance", *balance);

}

void deposit(double amount,double *balance, double *service, int *numDeposit, double *amtDeposit)

{

(*balance) += amount;

(*service) += 0.03;

(*numDeposit)++;

(*amtDeposit) += amount;

fprintf(fpOut, "Deposit \t%.2lf\t \t%.2lf ", amount, *balance);

printf("%s%19.2lf%31.2lf ", "Deposit", amount ,*balance);

}

void check(double amount,double *balance, double *service, int *numCheck, double *amtCheck)

{

if(amount < *balance)

{

(*balance) -= amount;

(*service) += 0.06;

}

if(*balance < 0.0)

{

(*service) += 5.00;

}

(*numCheck)++;

(*amtCheck) += amount;

fprintf(fpOut, "Check\t \t%.2lf\t \t%.2lf ", amount, *balance);

printf("%s%36.2lf%16.2lf ", "Check", amount ,*balance);

}

void outputSummary(int numDeposit,double amtDeposit, int numCheck, double amtCheck, double openBalance,double service, double closeBalance)

{

printf(" Total number deposits: %d ",numDeposit);

printf("Total amount deposits: %.2lf ",amtDeposit);

printf("Total number checks: %d ",numCheck);

printf("Total amount checks: %.2lf ",amtCheck);

printf("Total service charge: %.2lf ",service);

printf("Opening Balance: %.2lf ",openBalance);

printf("Closing Balance: %.2lf ",closeBalance);

fprintf(fpOut," Total number deposits: %d ",numDeposit);

fprintf(fpOut,"Total amount deposits: %.2lf ",amtDeposit);

fprintf(fpOut,"Total number checks: %d ",numCheck);

fprintf(fpOut,"Total amount checks: %.2lf ",amtCheck);

fprintf(fpOut,"Total service charge: %.2lf ",service);

fprintf(fpOut,"Opening Balance: %.2lf ",openBalance);

fprintf(fpOut,"Closing Balance: %.2lf ",closeBalance);

}

int main(void)

{

char code;

double amount, service, balance;

double amtcheck, amtDeposit, openBalance, closeBalance;

int numCheck, numDeposit;

if (!(fpIn = fopen("account.txt","r")))

{

printf("account.txt could not be opened for input.");

exit (1);

}

if (!(fpOut = fopen("csis.txt","w")))

{

printf("csis.txt could not be opened for output.");

exit (1);

}

amount = 0.0;

service = 0.0;

balance = 0.0;

amtcheck = 0.0;

amtDeposit = 0.0;

openBalance =0.0;

closeBalance = 0.0;

numCheck = 0;

numDeposit = 0;

outputHeaders ();

while (!feof(fpIn))

{

fscanf(fpIn, "%c %lf ", &code, &amount);

if (code == 'I')

{

initialBalance (amount, &balance,&service,&openBalance);

}

else if (code == 'D')

{

deposit(amount,&balance,&service,&numDeposit,&amtDeposit);

}

else

{

check( amount,&balance,&service,&numCheck,&amtcheck);

}

}

closeBalance = balance - service;

outputSummary(numDeposit, amtDeposit, numCheck, amtcheck, openBalance, service, closeBalance);

fclose(fpIn);

fclose(fpOut);

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!