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

Write a C program that allows the user to make some simple banking transactions

ID: 3553169 • Letter: W

Question

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 50 deposits and 50 withdrawals, 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 deposit (a positive amount to add to the bank account balance), the amount of the second deposit, the third, & etc., until the number of deposits have been processed.

Using a second loop, the program should then prompt the user to enter the amount of the first withdrawal (a positive amount to subtract from the bank account balance, if possible), the amount of the second withdrawal, the third, & , etc. until the number of withdrawals have been processed. Once all deposits and withdrawals have been made, the program should output the ending balance.

Read all the specifications carefully. I did not show all of the editing features you are required to do.

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


throws this error [Error] C:Program Files (x86)C-Free Standard empUntitled5.cpp:187: implicit declaration of function `int getch(...)'


#include <stdio.h>



int main(void)

{


/* Declaring variables */


int x, number_of_deposits, number_of_withdrawals;

float deposits[50], withdrawals[50];

float current_balance, balance;

float total_deposits = 0, total_withdrawals = 0;

char first_name[20];


/* Display of greeting */


printf("Welcome to the Air Force Credit Union Banking System. ");


/* Display to prompt the user's first name */

printf ("Please enter your first name: ");

scanf ("%s", first_name);

fflush(stdin);


/* Displays a simple greeting with the user's first name*/

printf(" Hello, %s. ", first_name);




do

{

/* Prompts the user to enter current balance*/

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

scanf ("%f",&current_balance);

fflush(stdin);


/* an error is display of the current balance is less than 0 dollars*/

if (current_balance < 0)

printf ("Error: Beginning balance must be at least zero, please re-enter! ");



}


/* this will end the loop if current balance is less than 0*/

while (current_balance < 0);


do

{

/* prompts the user to enter the amount of withdrawals*/

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

scanf ("%i",&number_of_withdrawals);

fflush (stdin);


/* a loop starts limiting the user on the amount of withdrawals*/

if (number_of_withdrawals < 0 || number_of_withdrawals > 50)

printf ("Error: Number of withdrawals must be between zero and 50, please re-enter! ");


}

/* If the amount of withdrawals is between 0 and 50 the loop ends*/

while (number_of_withdrawals < 0 || number_of_withdrawals > 50);


do

{

/* Prompts the user to enter amount of deposits*/

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

scanf ("%i",&number_of_deposits);

fflush (stdin);


/* loop starts with a display of an error message is amunt is less than 0 or over 50*/

if ( number_of_deposits < 0 || number_of_deposits > 50)

printf ("Error: Number of deposits must be between 0 and 50, please re-enter! ");


}

/* loop will stop if the amount is between 0 and 50 */

while (number_of_deposits < 0 || number_of_deposits > 50);


/* this will create a space to make it easy to read*/

printf(" ");



/* for loop starts and it will add the deposits entered, deposit needs to be positive*/

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

{


do

{

/* prompt to enter amount of deposits*/

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

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

fflush (stdin);



/* the loop will keep going until the amount is 0 or greater*/

if (deposits[x] <= 0)

printf ("*** Deposit amount must be greater than zero. Please re-enter! *** ");


}


while (deposits[x] <= 0);


/* new value to the total deposit will be created by adding the deposits */

total_deposits = total_deposits + deposits[x];


/*end for loop*/

}



/* space to make it easy to read*/

printf(" ");


/* starts for loop and the amount like in the deposits will be positive*/

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

{

do

{

/* prompts the user to enter amount of withdrawal*/

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

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

fflush (stdin);


/* this loops displays a message if the withdrawal amount is greater than the balance*/

if (withdrawals[x] > current_balance)

printf ("***Withdrawal amount exceeds current balance.*** ");

else


/* this loop will display a message if the amount is a negative amount*/

if (withdrawals[x] <= 0)

printf ("*** Withdrawal amout must be greater than zero. Please re-enter! *** ");


}

/* loop ends when amount is greater than 0 */

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


/* new value to the total withdrawal by adding the amount entered*/

total_withdrawals = total_withdrawals + withdrawals[x];



/* this will calculate the balance and ensures the withdrawal is less than the balance*/

balance = current_balance - total_withdrawals + total_deposits;


if (balance == 0)

{


/* if balance reach 0 then a message will be display and no more withdrawal allowed */

printf (" *** Balance is now zero. No more withdrawals can be made at this time. *** ");

number_of_withdrawals = x;

break;


}

/*end the loop*/

}



/* Calculate and display the closing balance */

/* the message displayed depends on the end balance*/

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



if (balance >= 50000.00)

printf ("*** %s, it is time to invest some money!*** ", first_name);

else if (balance >= 15000.00 && balance <= 49999.99)

printf ("*** %s, maybe you should consider a CD.*** ", first_name);

else if (balance >= 1000.00 && balance <= 14999.99)

printf ("*** %s, keep up the good work!*** ", first_name);

else

printf ("*** %s, your balance is getting low!*** ", first_name);


/* now the following is the display of the bank statement*/


printf (" *** Bank Statement *** ");


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


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

{

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

}


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

{

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


}


printf (" Ending Balance is :$ %7.2f ", balance);


{

getch();

return 0;

}

}

/* end main */


Explanation / Answer

#include <stdio.h>



int main(void)

{


/* Declaring variables */


int x, number_of_deposits, number_of_withdrawals;

float deposits[50], withdrawals[50];

float current_balance, balance;

float total_deposits = 0, total_withdrawals = 0;

char first_name[20];


/* Display of greeting */


printf("Welcome to the Air Force Credit Union Banking System. ");


/* Display to prompt the user's first name */

printf ("Please enter your first name: ");

scanf ("%s", first_name);

fflush(stdin);


/* Displays a simple greeting with the user's first name*/

printf(" Hello, %s. ", first_name);




do

{

/* Prompts the user to enter current balance*/

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

scanf ("%f",&current_balance);

fflush(stdin);


/* an error is display of the current balance is less than 0 dollars*/

if (current_balance < 0)

printf ("Error: Beginning balance must be at least zero, please re-enter! ");



}


/* this will end the loop if current balance is less than 0*/

while (current_balance < 0);


do

{

/* prompts the user to enter the amount of withdrawals*/

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

scanf ("%i",&number_of_withdrawals);

fflush (stdin);


/* a loop starts limiting the user on the amount of withdrawals*/

if (number_of_withdrawals < 0 || number_of_withdrawals > 50)

printf ("Error: Number of withdrawals must be between zero and 50, please re-enter! ");


}

/* If the amount of withdrawals is between 0 and 50 the loop ends*/

while (number_of_withdrawals < 0 || number_of_withdrawals > 50);


do

{

/* Prompts the user to enter amount of deposits*/

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

scanf ("%i",&number_of_deposits);

fflush (stdin);


/* loop starts with a display of an error message is amunt is less than 0 or over 50*/

if ( number_of_deposits < 0 || number_of_deposits > 50)

printf ("Error: Number of deposits must be between 0 and 50, please re-enter! ");


}

/* loop will stop if the amount is between 0 and 50 */

while (number_of_deposits < 0 || number_of_deposits > 50);


/* this will create a space to make it easy to read*/

printf(" ");



/* for loop starts and it will add the deposits entered, deposit needs to be positive*/

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

{


do

{

/* prompt to enter amount of deposits*/

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

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

fflush (stdin);



/* the loop will keep going until the amount is 0 or greater*/

if (deposits[x] <= 0)

printf ("*** Deposit amount must be greater than zero. Please re-enter! *** ");


}


while (deposits[x] <= 0);


/* new value to the total deposit will be created by adding the deposits */

total_deposits = total_deposits + deposits[x];


/*end for loop*/

}



/* space to make it easy to read*/

printf(" ");


/* starts for loop and the amount like in the deposits will be positive*/

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

{

do

{

/* prompts the user to enter amount of withdrawal*/

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

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

fflush (stdin);


/* this loops displays a message if the withdrawal amount is greater than the balance*/

if (withdrawals[x] > current_balance)

printf ("***Withdrawal amount exceeds current balance.*** ");

else


/* this loop will display a message if the amount is a negative amount*/

if (withdrawals[x] <= 0)

printf ("*** Withdrawal amout must be greater than zero. Please re-enter! *** ");


}

/* loop ends when amount is greater than 0 */

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


/* new value to the total withdrawal by adding the amount entered*/

total_withdrawals = total_withdrawals + withdrawals[x];



/* this will calculate the balance and ensures the withdrawal is less than the balance*/

balance = current_balance - total_withdrawals + total_deposits;


if (balance == 0)

{


/* if balance reach 0 then a message will be display and no more withdrawal allowed */

printf (" *** Balance is now zero. No more withdrawals can be made at this time. *** ");

number_of_withdrawals = x;

break;


}

/*end the loop*/

}



/* Calculate and display the closing balance */

/* the message displayed depends on the end balance*/

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



if (balance >= 50000.00)

printf ("*** %s, it is time to invest some money!*** ", first_name);

else if (balance >= 15000.00 && balance <= 49999.99)

printf ("*** %s, maybe you should consider a CD.*** ", first_name);

else if (balance >= 1000.00 && balance <= 14999.99)

printf ("*** %s, keep up the good work!*** ", first_name);

else

printf ("*** %s, your balance is getting low!*** ", first_name);


/* now the following is the display of the bank statement*/


printf (" *** Bank Statement *** ");


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


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

{

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

}


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

{

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


}


printf (" Ending Balance is :$ %7.2f ", balance);


{
return 0;

}

}

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