Question: Need help to fix my code: #define _CRT_SECURE_NO_WARNINGS #include FILE *fpIn, *fpOut; //Prototype variables void outputHeaders(void); void initialBalance(double amount, double *balance, double *service, double *openBalance);

Need help to fix my code:

#define _CRT_SECURE_NO_WARNINGS

#include

FILE *fpIn, *fpOut;

//Prototype variables

void outputHeaders(void);

void initialBalance(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);

int main(void)

{

char code;

double amount, service, balance;

double amtCheck, amtDeposit, openBalance, closeBalance;

int numCheck, numDeposit;

if (!(fpIn = fpopen("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.0;

numDeposit = 0.0;

outputHeader();

while (!feof(fpIn)) {

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

if (code == 'I') {

initalBalance(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);

system("pause");

return 0;

}

void outputHeaders()

{

printf("Transaction\t\t Deposit\t\t Check\t\t Balance ");

printf("-----------\t\t -------\t\t -----\t\t ------- ");

fprintf(fpOut, "Transaction\t\t Deposit\t\t Check\t\t Balance ");

fprintf(fpOut, "-----------\t\t -------\t\t -----\t\t ------- ");

}

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

{

*openBalance = amount;

*balance = *openBalance;

*service = 3.00;

printf("Initial Balance\t \t \t \t \t\t\t\t%8.2lf ", *openBalance);

fprintf(fpOut, "Initial Balance\t \t \t \t \t\t\t\t%8.2lf ", *openBalance);

}

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

{

*balance += amount;

*amtDeposit += amount;

*numDeposit += 1;

*service += 0.03;

printf("Deposit\t\t\t %8.2lf\t \t\t\t\t%8.2lf ", *amtDeposit, *balance);

fprintf(fpOut, "Deposit\t\t\t %8.2lf\t \t\t\t\t%8.2lf ", *amtDeposit, *balance);

}

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

{

*balance -= amount;

*amtCheck += amount;

*numCheck += 1;

if (*balance

*service += 5.00;

}

else {

*service += 0.06;

}

printf("Check\t\t\t\t\t\t %9.2lf\t\t%8.2lf ", *amtCheck, *balance);

fprintf(fpOut, "Check\t\t\t\t\t\t %9.2lf\t\t%8.2lf ", *amtCheck, *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("\tTotal number checks: %d ", numCheck);

printf("\tTotal amount checks: $%.2lf ", amtCheck);

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

printf("\tOpening balance: $%.2lf ", openBalance);

printf("\tClosing balance: $%.2lf ", closeBalance);

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

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

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

fprintf(fpOut, "\tTotal amount checks: $%.2lf ", amtCheck);

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

fprintf(fpOut, "\tOpening balance: $%.2lf ", openBalance);

fprintf(fpOut, "\tClosing balance: $%.2lf ", closeBalance);

}

output should look like this:

Need help to fix my code: #define _CRT_SECURE_NO_WARNINGS #include FILE *fpIn, *fpOut;

account.txt file:

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

ransaction Deposit Check Balance Initial Balance 478.83 606.28 1226.12 281.00 276.24 309.05 307.99 492.31 -2.87 -144.68 -399.78 -149.78 25.90 posit posit 127.45 619.84 Check Check 945.12 4.76 posit 32.81 Check Deposit Check 1.06 184.32 heck Check 495.18 141.81 255.10 posit Deposit Deposit Deposit heck Deposit heck 250.00 123.88 245.05 873.25 219.15 1092.40 981.12 111.28 317.84 429.12 812.73 -383.61 222.51 eposit 606.12 otal number deposits: 10 Total amount deposits: 3380.56 Total anount checks: 3636.88 Total service charge: 23.78 Opening balance: 478.83 Closing balance 198.73 Press any key to continue

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!