I am making a bank program with functions.1 called displaymenu that produces a menu d(make deposit),w(make withdraw),b(check balance) and
q(quit).2nd function is getdeposit which accepts balance as parameter and asks user for amount they want to deposit then add amount
to balance and return it to main function.3rd getwithdrawal same parameter (balance and subtract amount and return result)
last displaybalance it also accepts balance as parameter and displays currentbalance.then use a switch statement to select which function
to choose based on selection if they choose to quit respond thankyou.I have my switch statements but I have to implement a do while loop that asks the user if they want another tranaction. The screen asks if i want another transaction but instead of doing it it exits the program. can someone look over my code and suggest a fix?
#include <stdio.h>
char displaymenu();
float getdeposit(float amount,float balance);
float getwithdrawal(float amount,float balance);
float displaybalance(float balance);
int main()
{
char choice;
char transaction='y';
float deposit;
float withdrawal;
float balance;
float amount;
do {
choice=displaymenu();
switch (choice)
{
case 'd':case 'D':
printf("How much would you like to deposit?\n");
deposit=getdeposit(amount,balance);
break;
case 'w':case 'W':
printf("How much would you like to withdraw?\n");
if (((withdrawal== 0) || (withdrawal== -1))){
printf("You have insufficient funds");
}
else
{
withdrawal=getwithdrawal(amount,balance);
break;
}
case 'b':case 'B':
printf("Checking your account balance\n");
balance=displaybalance(balance);
break;
case 'q':case 'Q':
printf("Quit\n");
printf("Thankyou");
break;
default:
printf("Invalid Choice\n");
}
printf("\n\n\n DO U WISH TO HAVE ANOTHER TRANSCATION?(y/n): \n");
scanf("%c", &transaction);
} while
(transaction == 'y'|| transaction == 'Y');
return 0;
}
char displaymenu()
{
char choice;
printf("Welcome to Federal Credit Union!\n");
printf("Please select from the following menu\n");
printf("d. Make a deposit\n");
printf("w. Make a withdrawal\n");
printf("b. check balance\n");
printf("q. Quit\n");
scanf ("%c",&choice);
return choice;
}
float getdeposit(float amount,float balance)
{
float deposit;
deposit=amount+balance;
scanf ("%f",&deposit);
return deposit;
}
float getwithdrawal(float amount,float balance)
{
float withdrawal;
withdrawal=amount-balance;
scanf ("%f",&withdrawal);
return withdrawal;
}
float displaybalance(float balance)
{
printf("Your balance is %.2f\n",&balance);
}