Write a C program that will update a bank balance. A user cannot withdraw an amount ofmoney that is more than the current balance. The current balance must always be non-negativevalue. The variable types must be selected wisely. A sample run is below. The user’s response is in boldface (C by discovery)BANK ACCOUT PROGRAM!----------------------------------Enter the old balance: 1234.50Enter the transactions now.Enter an F for the transaction type when you are finished.Transaction Type (D=deposit, W=withdrawal, F=finished): DAmount: 568.34Transaction Type (D=deposit, W=withdrawal, F=finished): WAmount: 25.68Transaction Type (D=deposit, W=withdrawal, F=finished): WAmount: 167.40Transaction Type (D=deposit, W=withdrawal, F=finished): FYour ending balance is $1609.76Program is ending

Respuesta :

Answer:

Explanation:

Sample output:

BANK ACCOUT PROGRAM!

----------------------------------

Enter the old balance: 1234.50

Enter the transactions now.

Enter an F for the transaction type when you are finished.

Transaction Type (D=deposit, W=withdrawal, F=finished): D

Amount: 568.34

Transaction Type (D=deposit, W=withdrawal, F=finished): W

Amount: 25.68

Transaction Type (D=deposit, W=withdrawal, F=finished): W

Amount: 167.40

Transaction Type (D=deposit, W=withdrawal, F=finished): F

Your ending balance is $1609.76

Program is ending

Code to copy:

// include the necessary header files.

#include<stdio.h>

// Definition of the function

float withdraw(float account_balance, float withdraw_amount)

{

// Calculate the balace amount.

float balance_amount = account_balance - withdraw_amount;

// Check whether the withdraw amount

// is greater than 0 or not.

if (withdraw_amount > 0 && balance_amount >= 0)

{

// Assign value.

account_balance = balance_amount;

}

// return account_balance

return account_balance;

}

// Definition of the function deposit.

float deposit(float account_balance, float deposit_amount)

{

// Check whether the deposit amount is greater than zero

if (deposit_amount > 0)

{

// Update account balance.

account_balance = account_balance + deposit_amount;

}

// return account balance.

return account_balance;

}

int main()

{

// Declare the variables.

float account_balance;

float deposit_amount;

float withdrawl_amount;

char input;

// display the statement on console.

printf("BANK ACCOUT PROGRAM!\n");

printf("----------------------------------\n");

// prompt the user to enter the old balance.

printf("Enter the old balance: ");

// Input balance

scanf("%f", &account_balance);

// Display the statement on console.

printf("Enter the transactions now.\n");

printf("Enter an F for the transaction type when you are finished.\n");

// Start the do while loop

do

{

// prompt the user to enter transaction type.

printf("Transaction Type (D=deposit, W=withdrawal, F=finished): ");

// Input type.

scanf(" %c", &input);

// Check if the input is D

if (input == 'D')

{

// Prompt the user to input amount.

printf("Amount: ");

// input amount.

scanf("%f", &deposit_amount);

// Call to the function.

account_balance=deposit(account_balance,deposit_amount);

}

// Check if the input is W

if (input == 'W')

{

printf("Amount: ");

scanf("%f", &withdrawl_amount);

// Call to the function.

account_balance = withdraw(account_balance,withdrawl_amount);

}

// Check if the input is F

if (input == 'F')

{

// Dispplay the amount.

printf("Your ending balance is $%.2f\n", account_balance);

printf("Program is ending\n");

}

// End the while loop

} while(input != 'F');

return 0;

}

the picture uploaded below shows the program screenshot.

cheers, i hope this helps.

Ver imagen Preciousorekha1
Ver imagen Preciousorekha1
Ver imagen Preciousorekha1