Question: C PROGRAMMING: Hey, I've got most of the code down, and I know what I am missing! Help me fill in the missing code: The

C PROGRAMMING:

Hey, I've got most of the code down, and I know what I am missing! Help me fill in the missing code:

The missing code to be filled in has this notation /*** ... ***/

Program Description

Your program will read information from an input from a file that stores information about every transaction you friend makes. You may assume that your roommate has no more than 100 customers and each customer is labeled 0 through 99. An array has already been created to store information about these customers.

Your program will need to respond to three different commands:

Add a payment

Sell an item

Print messages for negative accounts

For commands of types 1 and 2, your program should update the appropriate customer account. A command of type one adds value to the account and a command of type two subtracts value from an account.

For commands of type 3, you should print out a message with the following format for each customer (in order of customer number) that has a negative account balance:

Customer X, you owe $Y. Please pay immediately!

where X is the account number and Y is the number of dollars owed (a positive amount).

If all accounts are paid properly, then print out the single line:

All accounts are paid up to date!!!

These commands will come from an input file.

Input File Format

The first line of the input file contains a single positive integer, n (n 1000), representing the number of commands to process. The commands follow, one per line.

Each command line will start with an integer, 1, 2 or 3, corresponding to the types of commands listed above. For command types 1 and 2, this will be followed with a space and a second integer, ID (0 ID 99), representing the identification number of the customer for the transaction. This will be followed by another space and a positive integer, v (v 100), representing the amount of dollars for the transaction. Commands of type 3 will have no further information following them.

Code:

#include

#define MAX_CUSTOMERS 100

int main() { // declare variables int numCommands, i, accounts[MAX_CUSTOMERS]; int command, id, amount, j, ok; char filename[20]; //***Declare File Pointer***/

// Open file. printf("What is the name of the file? "); scanf("%s", filename); //***Open Input File***/

// Initialize accounts. /***Set all values in accounts to zero***/

// Read the number of commands from the file fscanf(ifp, "%d", &numCommands);

// Process each command. for (i=0; i

// Get type of this command. /***Read command value from file***/

// Add money. if (command == 1) { /***Read id and amount from file***/ accounts[id] += amount; }

// Subtract money. else if (command == 2) { fscanf(ifp, "%d %d", &id, &amount); /***Deduct amount from the account with identification number id***/ }

// Print delinquents. else { // Go through each account, flagging negative balances. ok = 1; for (j=0; j/***check if jth account is less than zero***/) { printf("Customer %d, you owe $%d. Please pay immediately! ", j, -accounts[j]); ok = 0; } }

// Best case scenario. if (ok) printf("All accounts are paid up to date!!! ");

} }

//***close file pointer***/

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!