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

PROGRAMMING ASSIGNMENT #5 This program is similar to programming assignment #4.

ID: 3683321 • Letter: P

Question

PROGRAMMING ASSIGNMENT #5

This program is similar to programming assignment #4. That is, you will have all of the requirements as in Programming Assignment #4, including data error checking on all inputs.

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. Cannot use global variables.

Recall Programming Assignment #4:

Write a C program that allows the user to make some simple banking transactions. The program should first prompt the user to enter the current balance of his/her bank account (in dollars and cents, not less than zero). The program should then prompt the user to enter the number of withdrawals to make, and then the number of deposits to make. For this assignment, let's set a maximum of 5 deposits and 5 withdrawals (etc.)

Here is the change for program #5:

There should be at least two non-trivial functions in the program. (Non-trivial means that the function does more than simply print a line of text.)

Here are some examples of what you might want to use for your functions:

Input functions:

1. Obtain opening (current) balance.

2. Obtain number the number of deposits.

3. Obtain number of withdrawals.

4. Obtain deposit amounts.

5. Obtain withdrawal amounts.

Output functions:

1. Display closing balance and associated message.

2. Display message based on closing balance.

3. Display bank record.

Hints: Your code from assignment #4 does not need to be modified too much to solve this problem. The algorithm is the same. Outputting the contents of the arrays in "record form" is pretty straightforward, and should be done in a loop. (This could be a good place for a function.)

The most complicated of the above functions is the one which would display the bank record. If you decide that you want to attempt this one, I will give you a head start by providing the function header as shown here:

void (display_bank_record (float start_balance, float deposits [ ], int num_deposits, float withdrawals [ ], int num_withdrawals, float end_balance)

This is what was sent to me, but I cannot use global variables.

#include

#include

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

/* I have made these variables global so that every function can access*/

int x;

int num_deposits;

int num_withdrawals;

float current_balance, balance;

float total_deposits = 0;

float total_withdrawals = 0;

float deposits[50], withdrawals[50];

/* Functions Declarations ----------------------------------------- */

void inputBalance();

void inputWithdrawls_Deposit();

void display_bank_record (float start_balance, float deposits [ ], int num_deposits, float withdrawals [ ], int num_withdrawals, float end_balance) ; int main(int argc, char *argv[])

{

/* Greeting ----------------------------------------------------- */

/* -------------------------------------------------------------- */

printf ("Welcome to the Computer Banking System ");

printf (" "); // spaciNG //

*******Function Calling

inputBalance();

inputWithdrawls_Deposit();

for (x = 1; x <= num_deposits; ++x) { do { printf ("Enter the amount of deposit #%i: ", x);

scanf ("%f", &deposits[x]);

fflush (stdin);

if (deposits[x] <= 0)

{

printf ("***Deposit amount must be at least zero, please re-enter. ");

}

}

while (deposits[x] <= 0); total_deposits = total_deposits + deposits[x];

} printf (" "); // spacing

for (x = 1; x <= num_withdrawals; ++x)

{

do

{

printf ("Enter the amount of withdrawal #%i: ", x);

scanf ("%f", &withdrawals[x]);

if (withdrawals[x] < 0)

{

printf ("Withdrawal amount must be at least zero, please re-enter. ");

}

else

if (withdrawals[x] > current_balance)

{

printf ("***Withdrawal amount exceeds current balance, please re-enter. ");

}

/* do - if - else loop ends when amount is greater than 0 */

}

while (withdrawals[x] > current_balance || withdrawals[x] <=0);

total_withdrawals = total_withdrawals + withdrawals[x];

balance = current_balance - total_withdrawals + total_deposits;

if (balance == 0)

{

printf (" ***No more withdrawals allowed; current balance is 0.*** ");

num_withdrawals = x;

}

/* Closing Balance ------------------------------------------ */

/* ---------------------------------------------------------- */

printf (" "); // spacing

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

/* Message displayed will depend on closing balance.--------- */

/* ---------------------------------------------------------- */

if (balance >= 50000.00)

printf ("***It is time to invest some money!*** ");

else

if (balance >= 15000.00)

printf ("***Maybe you should consider a CD.*** ");

else

if (balance >= 1000.00)

printf ("***Keep up the good work!*** ");

else

if (balance >= 0)

printf ("Your balance is getting low!*** ");

}

/* end if-else loop */

/* Bank Record --------------------------------------------- */

/* --------------------------------------------------------- */

printf (" "); // spacing

printf ("***Bank Record*** ");

display_bank_record (current_balance, deposits, num_deposits, withdrawals, num_withdrawals, balance) ;

//function call system("PAUSE"); return 0;

}

/* ***Function Definations *****/ void inputBalance()

{

/* Prompt user to enter current balance. ----------------------- */

/* ------------------------------------------------------------- */

printf ("Enter your current balance in dollars and cents: ");

scanf ("%f", ¤t_balance); fflush (stdin);

while (current_balance < 0)

{

printf ("***Beginning balance must be at least zero, please re-enter. ");

scanf ("%f", ¤t_balance); fflush (stdin);

}

}

void inputWithdrawls_Deposit()

{

/* Prompt user to enter number of withdrawals. ------------------- */

/* --------------------------------------------------------------- */

printf (" "); // spacing

printf ("Enter the number of withdrawals (0 - 5): ");

scanf ("%i", &num_withdrawals); fflush (stdin);

/* Limits user to number of withdrawals between 0 and 5 */

while (num_withdrawals < 0 || num_withdrawals > 5)

{

printf ("***Invalid number of withdrawals, please re-enter. ");

scanf ("%i", &num_withdrawals);

fflush (stdin);

}

do

{

/* Prompt user to enter number of deposits. ------------------------ */

/* ----------------------------------------------------------------- */

printf (" "); // spacing

printf ("Enter the number of deposits (0 - 5): ");

scanf ("%i", &num_deposits); fflush (stdin);

/* Limits user to number of deposits between 0 and 5 */

if (num_deposits < 0 || num_deposits > 5)

printf ("***Invalid number of deposits, please re-enter.");

}

while (num_deposits < 0 || num_deposits > 5);

}

void display_bank_record (float start_balance, float deposits [ ], int num_deposits, float withdrawals [ ], int num_withdrawals, float end_balance)

{

/****Starting Balance****/

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

/****total deposits****/

for (x = 1; x <= num_deposits; ++x)

{

printf ("Deposit #%i: %.2f ", x, deposits[x]);

}

printf (" ");

/****total Wihdrawls****/

for (x = 1; x <=num_withdrawals; ++x)

{

printf ("Withdrawal #%i: %.2f ", x, withdrawals[x]);

}

/* end for loop */ printf (" ");

/****Endng Balance****/

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

}

Explanation / Answer

#include
#include
/* Variable Declarations ----------------------------------------- */
/* I have made these variables global so that every function can access*/

/* Functions Declarations ----------------------------------------- */
void inputBalance(&current_balance, &balance);
void inputWithdrawls_Deposit();
void inputDeposits(int &num_deposits);
void depositAmounts(int num_deposits, int &total_deposits);
void withdrawlAmounts(int num_withdrawals, int &total_withdrawals);

void display_bank_record (float start_balance, float deposits [ ], int num_deposits, float withdrawals [ ], int num_withdrawals, float end_balance) ;
int main(int argc, char *argv[])
{
int x;
int num_deposits;
int num_withdrawals;
float current_balance, balance;
float total_deposits = 0;
float total_withdrawals = 0;
float deposits[50], withdrawals[50];
/* Greeting ----------------------------------------------------- */
/* -------------------------------------------------------------- */
printf ("Welcome to the Computer Banking System ");
printf (" "); // spaciNG //
*******Function Calling
inputBalance(&current_balance, &balance);
inputWithdrawls_Deposit(&num_withdrawals);

for (x = 1; x <= num_deposits; ++x) {
do { printf ("Enter the amount of deposit #%i: ", x);
scanf ("%f", &deposits[x]);
fflush (stdin);
if (deposits[x] <= 0)
{
printf ("***Deposit amount must be at least zero, please re-enter. ");
}
}
while (deposits[x] <= 0); total_deposits = total_deposits + deposits[x];
}
printf (" "); // spacing
for (x = 1; x <= num_withdrawals; ++x)
{
do
{
printf ("Enter the amount of withdrawal #%i: ", x);
scanf ("%f", &withdrawals[x]);
if (withdrawals[x] < 0)
{
printf ("Withdrawal amount must be at least zero, please re-enter. ");
}
else
if (withdrawals[x] > current_balance)
{
printf ("***Withdrawal amount exceeds current balance, please re-enter. ");
}
/* do - if - else loop ends when amount is greater than 0 */
}
while (withdrawals[x] > current_balance || withdrawals[x] <=0);
total_withdrawals = total_withdrawals + withdrawals[x];
balance = current_balance - total_withdrawals + total_deposits;
if (balance == 0)
{
printf (" ***No more withdrawals allowed; current balance is 0.*** ");
num_withdrawals = x;
}
/* Closing Balance ------------------------------------------ */
/* ---------------------------------------------------------- */
printf (" "); // spacing
printf ("***The closing balance is %.2f*** ", balance);
/* Message displayed will depend on closing balance.--------- */
/* ---------------------------------------------------------- */
if (balance >= 50000.00)
printf ("***It is time to invest some money!*** ");
else
if (balance >= 15000.00)
printf ("***Maybe you should consider a CD.*** ");
else
if (balance >= 1000.00)
printf ("***Keep up the good work!*** ");
else
if (balance >= 0)
printf ("Your balance is getting low!*** ");
}
/* end if-else loop */
/* Bank Record --------------------------------------------- */
/* --------------------------------------------------------- */
printf (" "); // spacing
printf ("***Bank Record*** ");
display_bank_record (current_balance, deposits, num_deposits, withdrawals, num_withdrawals, balance) ;
//function call system("PAUSE"); return 0;
}
/* ***Function Definations *****/ void inputBalance(float current_balance, float balance)
{
/* Prompt user to enter current balance. ----------------------- */
/* ------------------------------------------------------------- */
printf ("Enter your current balance in dollars and cents: ");
scanf ("%f", ¤t_balance); fflush (stdin);
while (current_balance < 0)
{
printf ("***Beginning balance must be at least zero, please re-enter. ");
scanf ("%f", ¤t_balance); fflush (stdin);
}
}
void inputWithdrawls_Deposit(int num_withdrawals)
{
/* Prompt user to enter number of withdrawals. ------------------- */
/* --------------------------------------------------------------- */
printf (" "); // spacing
printf ("Enter the number of withdrawals (0 - 5): ");
scanf ("%i", &num_withdrawals); fflush (stdin);
/* Limits user to number of withdrawals between 0 and 5 */
while (num_withdrawals < 0 || num_withdrawals > 5)
{
printf ("***Invalid number of withdrawals, please re-enter. ");
scanf ("%i", &num_withdrawals);
fflush (stdin);
}
do
{
/* Prompt user to enter number of deposits. ------------------------ */
/* ----------------------------------------------------------------- */
printf (" "); // spacing
printf ("Enter the number of deposits (0 - 5): ");
scanf ("%i", &num_deposits); fflush (stdin);
/* Limits user to number of deposits between 0 and 5 */
if (num_deposits < 0 || num_deposits > 5)
printf ("***Invalid number of deposits, please re-enter.");
}
while (num_deposits < 0 || num_deposits > 5);
}
void display_bank_record (float start_balance, float deposits [ ], int num_deposits, float withdrawals [ ], int num_withdrawals, float end_balance)
{
/****Starting Balance****/
printf ("Starting Balance: $%.2f ", current_balance);
/****total deposits****/
for (x = 1; x <= num_deposits; ++x)
{
printf ("Deposit #%i: %.2f ", x, deposits[x]);
}
printf (" ");
/****total Wihdrawls****/
for (x = 1; x <=num_withdrawals; ++x)
{
printf ("Withdrawal #%i: %.2f ", x, withdrawals[x]);
}
/* end for loop */ printf (" ");
/****Endng Balance****/
printf ("Ending Balance: $%.2f ", balance); printf (" ");
}
void inputDeposits(int num_deposits){
printf("total deposits: ");
scanf("%d",&num_deposits);
}

void depositAmounts(int num_deposits, int total_deposits){
int i;
float temp;
for(i=0;i<num_deposits;i++){
printf("Enter deposits: ");
scanf("%f",&temp);
total_deposits = total_deposits + temp;
}
}

void withdrawlAmounts(int num_withdrawals, int total_withdrawals){
int i;
float temp;
for(i=0;i<num_withdrawals;i++){
printf("Enter withdrawls: ");
scanf("%f",&temp);
total_withdrawals = total_withdrawals + temp;
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote