please write the program in C language. and I am having hard time to do the do~w
ID: 3847774 • Letter: P
Question
please write the program in C language.
and I am having hard time to do the do~while loop allowing the customer to complete another transaction. for some reason when customer response Y it doesnt work.
So in total there should be 4 functions.
1. displayMenu
2. getDeposit
3.getWithdrawl
4.displayBalance.
all cases must use data validation (within data type). each function that requires input from the users should have its own data validation loop.
thank you.
Name Grade: Bank Function Programming Assignment 1) create a function called displayMenu() that produces a menu that looks like the following- Welcome to HFC Federal Credit Union Please select from the following menu: D: Make a deposit W: Make a withdrawal B: Check your account balance Q: To quit The function should then accept the user's choice from the menu and return it to the main function. 2 Create a function called eetDepositI) that accepts the current balance as a parameter and asks the user for the amount that they would like to deposit. Your function must then add that amount to the current balance and return the result to the main function. 3) create a function called drawal that accepts the current balance as a parameter and asks the user for the amount that they would like to withdraw. Your function must then subtract that amount from the current balance and return the result to the main 4) create a function called displayBalancell that accepts the current balance as a parameter and displays the current balance. 5) Using the above functions, create the main function to do the following: a. Display the menu b. use a switch statement to select which function to choose based on the user's selection. If the user chooses to quit, respond with "Thank You If the user chooses an invalid selection, produce an error message c. Once it works, put it into a do while loop allowing the user to complete another transaction- 6) In all cases, you must complete data validation (within data types. Each function that requires input from the user should have it's own data validation loop. 7) Once complete, upload the (cor cpp) file to Moodle attach a copy af the source code to this sheet and turn it in during class on the due date.Explanation / Answer
#include<stdio.h>
#include<stdlib.h>
void displayMenu(){
printf(" Welcome to HDFC Federal Credit Union!! ");
printf(" Please Select from the following menu ");
printf("D: Make a Deposit ");
printf("W: Make a Withdrawl ");
printf("B: Check your account balance ");
printf("Q: To Quit ");
}
float getDeposit(float current, float amount)
{
float total;
total = current+amount;
return total;
}
float getWithdrawl(float current){
float withdrawl, total;
printf(" Enter the amount to be withdrawl : ");
scanf("%f",&withdrawl);
total = current-withdrawl;
return total;
}
void displayBalance(float current){
printf(" Your curren account balance is : %f",current);
}
int main(void){
float current=0, amount=0;
char selection=' ';
do{
selection=' ';
displayMenu();
scanf("%c",&selection);
switch(selection){
case 'D': printf("Enter the current Bank account : ");
scanf("%f",¤t);
printf("Enter the amount to be deposit : ");
scanf("%f",&amount);
current = getDeposit(current, amount);
break;
case 'W': current = getWithdrawl(current);
break;
case 'B': displayBalance(current);
break;
case 'Q': printf("Thank You!!");
break;
default: printf("ERROR!! Please select from abve Menu");
break;
}
printf(" You entered %c ",selection);
}while((selection != 'Q')||(selection != 'q'));
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.