Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

My professor has provided us with a sample program to use it as a guide, but not

ID: 3642620 • Letter: M

Question

My professor has provided us with a sample program to use it as a guide, but not to copy his work. See below:



/*---------------------------------------------------------------
Program file: ledger.c
Author: Jim Sears
Assignment: #4
Course #: 90.211.031
Objective:
This program allows the user 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 25 credits or debits, you'll see why as you read on.
Arrays are used and a ledger record prints out at the end.
Sample run:
Welcome to the Sears Ledger System

Please enter the ledger Account name: Trip Expenses

The program will allow you to enter credits and debits to the Trip Expenses account.

Please enter the Trip Expenses current balance in dollars and cents: 256.40

Enter the number of debits to post: 2

Enter the number of credits to post: 3

Enter the amount of credit #1: 10.50
Enter the amount of credit #2: 12.25
Enter the amount of credit #3: 125.30

Enter the amount of debit #1: 120.35
Enter the amount of debit #2: 35.60

*** The Trip Expense balance is $248.50 ***



*** Ledger Record ***
Trip Expenses

Starting Balance: $ 256.40

credit #1: 10.50
credit #2: 12.25
credit #3: 125.30

debit #1: 120.35
debit #2: 35.60

Ending Balance: $ 248.50


---------------------------------------------------------------*/
#include <stdio.h>
#define MAX 25
void main (void)
{

/* Variable Declarations */
/* --------------------- */

int number_of_credits, number_of_debits, i;
float amount_to_credit[50], amount_to_debit[50];
float starting_balance, current_balance;
char name[30];

/* Display an introduction header */
/* ------------------------------ */

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

printf("Please enter the ledger Account name: ");
gets(name);
fflush(stdin);

printf(" The program will allow you to enter credits and debits "
"to the %s account. ", name);

/* Query the user for the starting balance (starting_balance >= 0) */
/* ------------------------------------------------------------ */

do
{
printf ("Please enter the %s current balance in dollars and cents: ", name);
scanf("%f", &starting_balance);
fflush(stdin);

if (starting_balance < 0)
printf("Error: Starting Balance must be at least zero! ");

} while (starting_balance < 0);

/* Prompt for the number of debits */
/* Ensure that user did not enter more than 50 debits. */
/* -------------------------------------------------------- */

do
{
printf (" Enter the number of debits to post: ");
scanf ("%i", &number_of_debits);
fflush(stdin);

if (number_of_debits > MAX)
printf ("*** Too many debits. *** ");
if (number_of_debits < 0)
printf ("*** Negative number of debits not allowed. *** ");

} while (number_of_debits > MAX || number_of_debits < 0);


/* Prompt for the number of credits. */
/* Ensure that user did not enter more than 50 credits. */
/* ----------------------------------------------------- */

do
{
printf (" Enter the number of credits to post: ");
scanf ("%i", &number_of_credits);
fflush(stdin);

if (number_of_credits > MAX)
printf ("*** Too many credits. Only %i allowed! *** ", MAX);
if (number_of_credits < 0)
printf ("*** Negative number of credits not allowed. *** ");

} while ( number_of_credits > MAX || number_of_credits < 0);



/* Retain starting balance for ledger record. */
/* ---------------------------------------- */

current_balance = starting_balance;

/* Prompt for all credit amounts, keeping track of current balance. */
/* ---------------------------------------------------------------- */

printf (" "); /* spacing */

for (i = 0; i < number_of_credits; i++ )
{
do
{
printf ("Enter the amount of credit #%i: ", i+1 );
scanf ("%f", &amount_to_credit[i]);
fflush(stdin);

if (amount_to_credit[i] <= 0)
printf ("*** credit amount must be positive! Please re-enter *** ");

} while (amount_to_credit[i] <= 0);

current_balance = current_balance + amount_to_credit[i];

} /* end for loop */


/* Prompt for all debit amounts, keeping track of current balance. */
/* ------------------------------------------------------------------- */


printf (" "); /* spacing */
for (i = 0; i < number_of_debits; i++ )
{
/* Enter debit amounts */
/* ------------------- */

do
{
printf ("Enter the amount of debit #%i: ", i+1 );
scanf ("%f", &amount_to_debit[i]);
fflush(stdin);

if (amount_to_debit[i] <= 0)
printf ("*** debit amount must be greater than zero! *** ");

} while (amount_to_debit[i] <= 0);

current_balance = current_balance - amount_to_debit[i];


} /* end for loop.*/
printf (" "); /* spacing */


/* Output closing balance and appropriate closing message. */
/* ------------------------------------------------------- */

printf ("*** The %s balance is $%.2f *** ", name, current_balance);

if (current_balance > 0 )
printf ("*** The account %s has a credit balance ***", name);
else
if (current_balance == 0 )
printf ("*** The account %s is now exhausted of funds ***", name);
else
if (current_balance < 0 )
printf ("*** The account %s is now over the allotted budget ***", name);


/* Output ledger record: Starting balance, credits and debits. */
/* ------------------------------------------------------------- */

printf (" "); /* spacing */

printf (" *** Ledger Record *** %s ", name);
printf ("Starting Balance:$%13.2f ", starting_balance);

for (i = 0; i < number_of_credits; i++ )
printf ("credit #%2.i: %13.2f ", i+1, amount_to_credit[i]);

if (number_of_credits > 0)
printf (" "); /* spacing */

for (i = 0; i < number_of_debits; ++i )
printf ("debit #%2.i: %13.2f ", i+1, amount_to_debit[i]);

printf (" Ending Balance: $%13.2f ", current_balance);

getchar();

} /* end main. */





This program is similar to programming assignment #4: Data error checking is required for all inputs, as in #4. Your program is to behave in the exact same manner as assignment #4, however how you structure your code is a different story. Now we will use functions.

Hmmmmmmm, I think I remember Assignment #4, lets see

Explanation / Answer

if you need help contact me at cuttup666@gmail.com

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote