From 57a64876bec841c4a6076de6f66ffa614d9fdb99 Mon Sep 17 00:00:00 2001 From: Shivam Chaudhary Date: Wed, 1 Feb 2023 21:05:53 +0100 Subject: [PATCH] Add missing parameter to function and organise code --- src/withdrawMoney.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) 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");