diff --git a/src/withdrawMoney.c b/src/withdrawMoney.c index b3165d0..2c3e621 100644 --- a/src/withdrawMoney.c +++ b/src/withdrawMoney.c @@ -1,23 +1,17 @@ #include "withdrawMoney.h" -void initiateWithdraw(float amountToWithdraw, float availableAccountBalance) { - char returnToHomeInput = NULL; +float initiateWithdraw(float amountToWithdraw, float availableAccountBalance) { + float remainingAccountBalance = (availableAccountBalance - amountToWithdraw); - updateAccountBalance(remainingAccountBalance); - printf("You have successfully withdrawn %f €.\n", amountToWithdraw); - printf("Remaining account balance: %f €\n\n", remainingAccountBalance); - printf("Press any key to return to home page: "); - scanf("%c", &returnToHomeInput); - - if (returnToHomeInput) { - showAllMenuEntries(); - } + return remainingAccountBalance; } void withdraw(int user_id) { float amountToWithdraw; char tryDifferentAmount; + float remainingAccountBalance; + bool updateSuccess = false; printf("Enter amount to withdraw: "); scanf("%f", &amountToWithdraw); @@ -25,7 +19,12 @@ void withdraw(int user_id) { float availableAccountBalance = getAvailableAccountBalance(user_id); if (amountToWithdraw > 0) { if (amountToWithdraw <= availableAccountBalance) { - initiateWithdraw(amountToWithdraw, availableAccountBalance); + remainingAccountBalance = initiateWithdraw(amountToWithdraw, availableAccountBalance); + updateSuccess = updateAccountBalance(user_id, remainingAccountBalance); + if( updateSuccess ) { + notifyCustomer(); + } + } else { printf("You don't have sufficient money to withdraw. Do you want to try different amount?\n[y]: Yes, any other key : exit");