Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This program is similar to programming assignment #4. This program is similar to programming assignment #4. That is, you will have all of the requirements

This program is similar to programming assignment #4.

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. 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)

Here is what I have so far

/* This program completes simple banking transactions per user */

#include

int main (void) { /* declaring variables */ /*---------------------*/ int x ; int number_of_deposits; int number_of_withdrawals; float deposits[5]; float withdrawals[5]; float current_balance; float balance =0; float total_deposits = 0; float total_withdrawals = 0; /* display greeting to user */ /*---------------------*/ printf("Welcome to the Computer Banking System "); do { /* Enter Current Balance */ /*------------------------*/ printf ("Enter your current balance in dollars and cents: "); scanf ("%f",¤t_balance); fflush(stdin); /* Error if current balance entered is less than zero dollars */ /*------------------------------------------------------------*/ if (current_balance < 0) printf ("*** Beginning balance must be at least zero, please re-enter. "); } /* End Loop */ /*--------------*/ while (current_balance < 0); do { /* Enter the number of deposits that will be made */ /*--------------------------------------*/ printf (" Enter the number of deposits (0 - 5): "); scanf ("%i",&number_of_deposits); fflush (stdin); /* Limit amount of deposits */ /*--------------------------*/ if (number_of_deposits < 0 || number_of_deposits > 5) printf ("*** Invalid number of deposits, please re-enter. "); } /* End Loop */ /*----------*/ while (number_of_deposits < 0 || number_of_deposits > 5); do { /* Enter the numbers of withdrawals that will be made */ /*------------------------------------------*/ printf (" Enter the number of withdrawals (0 - 5): "); scanf ("%i",&number_of_withdrawals); fflush (stdin); printf(" "); /* Limit amount of withdrawals */ /*-----------------------------*/ if ( number_of_withdrawals < 0 || number_of_withdrawals > 5) printf ("*** Invalid number of withdrawals, please re-enter. "); } /* Loop stops if value is between 0 and 5 */ /*----------------------------------------*/ while (number_of_withdrawals < 0 || number_of_withdrawals > 5); /* Add the deposits entered */ /*--------------------------*/ for (x = 1; x <= number_of_deposits; x++) { do { /* Enter dollar value of deposits */ /*--------------------------------*/ printf ("Enter the amount of deposit #%i: ", x); scanf ("%f",&deposits[x]); fflush (stdin); /* loop until the amount is zero or greater */ /*------------------------------------------*/ if (deposits[x] <= 0) printf ("*** Deposit amount must be greater than zero. Please re-enter. "); } while (deposits[x] <= 0); /* Total deposit will be created by adding the deposits value */ /*------------------------------------------------------------*/ total_deposits = total_deposits + deposits[x]; /*End Loop*/ /*--------*/ } printf(" "); /* Start loop and the amount in the deposits will be positive */ /*------------------------------------------------------------*/ for (x = 1; x <= number_of_withdrawals; x++) { do { /* Enter dollar value of withdrawals */ /*-----------------------------------*/ printf ("Enter the amount of withdrawal #%i: ", x); scanf ("%f",&withdrawals[x]); fflush (stdin); /* Prompt if the withdrawal amount is greater than the balance */ /*-------------------------------------------------------------*/ if (withdrawals[x] > current_balance) printf ("*** Withdrawal amount exceeds current balance. "); else /* Prompt if the amount is a negative amount */ /*-------------------------------------------*/ if (withdrawals[x] <= 0) printf ("*** Withdrawal amount must be greater than zero. Please re-enter. "); } /* Lnd Loop */ /*----------*/ while (withdrawals[x] > current_balance || withdrawals[x] <= 0); /* Lotal withdrawal by adding the amount entered */ /*-----------------------------------------------*/ total_withdrawals = total_withdrawals + withdrawals[x]; /* Calculate the balance & validate withdrawal is less than the balance */ /*----------------------------------------------------------------------*/ balance = current_balance - total_withdrawals + total_deposits; if (balance == 0) { /* If balance is zero then display with "no more withdrawals" */ /*-----------------------------------------------------------*/ printf (" *** Balance is now zero. No more withdrawals can be made at this time. *** "); number_of_withdrawals = x; break; } /* End Loop */ /*----------*/ } /* Calculate and display the closing balance */ /*-------------------------------------------*/ printf (" *** The closing balance is $%.2f *** ", balance); if (balance >= 50000.00) printf ("*** It is time to invest some money! *** "); else if (balance >= 15000.00 && balance <= 49999.99) printf ("*** Maybe you should consider a CD.*** "); else if (balance >= 1000.00 && balance <= 14999.99) printf ("*** Keep up the good work! *** "); else printf ("*** Your balance is getting low! *** "); /* Display the bank statement */ /*----------------------------*/ printf (" *** Bank Record *** "); printf (" Starting Balance:$ %6.2f ", current_balance); for (x = 1; x <= number_of_deposits; x++) { printf ("Deposit #%i: %13.2f ", x, deposits[x]); } for ( x = 1; x<= number_of_withdrawals; x++) { printf (" Withdrawal #%i: %10.2f", x, withdrawals[x]); } printf (" Ending Balance:$%9.2f ", balance); //return 0; system("pause"); /* End Main */ }

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

Microsoft Visual Basic 2008 Comprehensive Concepts And Techniques

Authors: Gary B. Shelly, Corinne Hoisington

1st Edition

1423927168, 978-1423927167

More Books

Students also viewed these Databases questions

Question

What is a management control system?

Answered: 1 week ago