This is a standard bank account program. Allowing for deposit,withdrawal,and viewing funds. I am having trouble getting the program to enter the functions inside my switch statement which is based on their choice. Here is the output of this code. CodeOutput. I am not asking anyone to code for me, if you could maybe just point to where I went wrong.
#include <stdio.h>
float getDeposit(float currentBalance);
float getWithdrawal(float currentBalance);
float displayBalance(float currentBalance);
char displayMenu();
int main()
{
float currentBalance=200,newBalanceDep,newBalanceWith;
char choice;
choice = displayMenu();
switch (choice)
{
case 'D': case 'd':
newBalanceDep=getDeposit(currentBalance);
break;
case 'W': case 'w':
newBalanceWith=getWithdrawal(currentBalance);
break;
case 'B': case 'b':
displayBalance(currentBalance);
break;
case 'Q': case 'q':
printf("Thank you!");
break;
default:
printf("Invalid choice.");
break;
}
return 0;
}
char displayMenu()
{
char choice;
printf("Welcome to HFC 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 your account balance \n");
printf("Q: To quit \n");
scanf("\n%c",choice);
return choice;
}
float getDeposit(float currentBalance)
{
float depositAmount;
float newBalanceDep;
printf("Enter amount you would like to deposit: /n");
scanf("%f",&depositAmount);
if(depositAmount>0)
{
newBalanceDep=depositAmount+currentBalance;
}
return newBalanceDep;
}
float getWithdrawal(float currentBalance)
{
float withdrawalAmount;
float newBalanceWith;
printf("Enter amount you would like to withdrawal: /n");
scanf("%f",&withdrawalAmount);
if(withdrawalAmount>currentBalance)
{
printf("Insufficient Funds. Try again.");
printf("Enter amount you would like to withdrawal: /n");
scanf("%f",&withdrawalAmount);
}
else if(withdrawalAmount<=currentBalance)
{
newBalanceWith=withdrawalAmount+currentBalance;
}
return newBalanceWith;
}
float displayBalance(float currentBalance)
{
printf("Your current balance is %.2f",currentBalance);
}