Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please modify the following compiled code with the following three FUNCTION PROTOTYPES 2 arguments(input) return a float(output 1 argument(input) 'return' a char array(output) 2 arguments(input)

Please modify the following compiled code with the following three FUNCTION PROTOTYPES

2 arguments(input) return a float(output

1 argument(input) 'return' a char array(output)

2 arguments(input) 'return' an int array(output) 

Please indicate some comment that will help the code readability.

Please provide the output you got.

====================================================

include

int main(void)

{

/* declare variables */

char acctName[20];

float startBalance,closingBalance,credits[50],debits[50];

int i,numDebits,numCredits;

char c;

// declare account introduction

printf(" Welcome to the Sears Accounting System ");

/* Prompt user for name of the account. */

printf(" First, enter the name of the Account: ");

scanf("%s",acctName);

while(c = getchar() != ' '); /* clear input buffer */

printf(" Now enter the %s balance in dollars and cents: ", acctName);

scanf("%f",&startBalance);

while(c = getchar() != ' '); /* clear input buffer */

printf(" Enter the number of debits: ");

scanf("%d",&numDebits);

while(c = getchar() != ' '); /* clear input buffer */

if(numDebits > 50)

{

printf(" Error: Number of debits must be at most 50,please re-enter.");

printf(" Enter the number of debits: ");

scanf("%d",&numDebits);

while(c = getchar() != ' '); /* clear input buffer */

}

printf(" Enter the number of credits: ");

scanf("%d",&numCredits);

while(c = getchar() != ' '); /* clear input buffer */

if(numCredits > 50)

{

printf(" Error: Number of credits must be at most 50,please re-enter.");

printf(" Enter the number of credits: ");

scanf("%d",&numCredits);

while(c = getchar() != ' '); /* clear input buffer */

}

for(i=0;i

{

printf(" Enter the amount of credit #%d: ",(i+1));

scanf("%f",&credits[i]);

while(c = getchar() != ' '); /* clear input buffer */

} /*end of for loop*/

closingBalance = startBalance;

for(i=0;i

{

closingBalance = closingBalance + credits[i];

}

for(i=0;i

{

printf(" Enter the amount of debit #%d: ",(i+1));

scanf("%f",&debits[i]);

while(c = getchar() != ' '); /* clear input buffer */

}

for(i=0;i

{

closingBalance = closingBalance - debits[i];

}/*end of for loop*/

printf(" *** The closing balance is $ %.2f ***",closingBalance);

printf(" *** Account %s Summary *** ",acctName);

printf(" Starting Balance: $ %.2f ",startBalance);

for(i=0;i

{

printf(" credit # %d: %14.2f",(i+1),credits[i]);

}/*end of for loop*/

for(i=0;i

{

printf(" debit # %d: %14.2f",(i+1),debits[i]);

} /*end of for loop*/

printf(" Ending Balance: $ %.2f ",closingBalance);

getchar();

return 0;

} /* end main */

==============================

Original problems from where the above code was compiled is as below:

Write a C program that allows the user to make some ledger transactions. The program should first prompt the user to enter the current balance of his/her ledger account (must allow for dollars and cents, and not less than zero). The program should then prompt the user to enter the number of debits to be posted, and then the number of credits to be posted. For this assignment, let's set a maximum of 50 credits or debits, you'll see why as you read on. Using a loop, the program should then prompt the user to enter the amount of the first credit (a positive amount to add to the ledger balance), the amount of the second, the third, & etc., until the number of credits have been processed. Using a second loop, the program should then prompt the user to enter the amount of the first debit (a positive amount to be subtracted from the ledger balance), then amount of the second, the third, etc. until the number of debits have been processed. Once all credits and debits have been made, the program should output the ledger balance. Read all the specifications carefully. I did not show all of the editing features you are required to do, but they are in bold above.

The dialog with the user should look similar to the following, only with your special introductory statement(s) as you wish:

Welcome to the Sears Accounting System

First, enter the name of the Account: Electrical

Now enter the Electrical balance in dollars and cents: 200.55

Enter the number of debits: 2

Enter the number of credits: 55

Error: Number of credits must be at most 50,

please re-enter. Enter the number of credits: 7

Enter the amount of credit #1: 12

Enter the amount of credit #2: 13.22

Enter the amount of credit #3: 11

Enter the amount of credit #4: 40

Enter the amount of credit #5: 33

Enter the amount of credit #6: 22.22

Enter the amount of credit #7: 33

Enter the amount of debit #1: 111

Enter the amount of debit #2: 222

*** The closing balance is $31.99 ***

*** Account Electrical Summary ***

Starting Balance: $ 200.55

credit # 1: 12.00

credit # 2: 13.22

credit # 3: 11.00

credit # 4: 40.00

credit # 5: 33.00

credit # 6: 22.22

credit # 7: 33.00

debit # 1: 111.00

debit # 2: 222.00

Ending Balance: $ 31.99

There should be error checking on all user input, and trap loops need to be used. It is hard to see this in HTML document, but I want you to align the decimal points in the account summary. You are to keep track of all of the credits and debits so that you can print them out in "record" form. You do this by storing them in arrays. You want to be sure that the size of the arrays are large enough to handle 50 credits and 50 debits. Perhaps: float credits[50], debits [50];

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

MongoDB Applied Design Patterns Practical Use Cases With The Leading NoSQL Database

Authors: Rick Copeland

1st Edition

1449340040, 978-1449340049

More Books

Students also viewed these Databases questions

Question

Define abstraction and explain how it relates to OLE DB.

Answered: 1 week ago

Question

a. Describe the encounter. What made it intercultural?

Answered: 1 week ago