diff --git a/src/withdrawMoney.c b/src/withdrawMoney.c new file mode 100644 index 0000000..5502fec --- /dev/null +++ b/src/withdrawMoney.c @@ -0,0 +1,59 @@ +#include "withdrawMoney.h" + +void notifyCustomer(amountToWithdraw, remainingAccountBalance) { + char returnToHomeInput = NULL; + + 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(); + } +} + +float initiateWithdraw(float amountToWithdraw, float availableAccountBalance) { + float remainingAccountBalance = (availableAccountBalance - amountToWithdraw); + + return remainingAccountBalance; +} + +void withdraw(int user_id) { + float amountToWithdraw; + char tryDifferentAmount; + float remainingAccountBalance; + bool updateSuccess = false; + + printf("Enter amount to withdraw: "); + scanf("%f", &amountToWithdraw); + + float availableAccountBalance = getAvailableAccountBalance(user_id); + if (amountToWithdraw > 0) { + if (amountToWithdraw <= availableAccountBalance) { + remainingAccountBalance = initiateWithdraw(amountToWithdraw, availableAccountBalance); + updateSuccess = updateAccountBalance(user_id, remainingAccountBalance); + if( updateSuccess ) { + notifyCustomer(amountToWithdraw, remainingAccountBalance); + } + else { + printf("Some error occured! Sorry for the inconvenience caused.\n"); + } + + } + else { + printf("You don't have sufficient money to withdraw. Do you want to try different amount?\n[y]: Yes, any other key : exit"); + scanf("%c", &tryDifferentAmount); + if (tryDifferentAmount == 'Y' || tryDifferentAmount == 'y') { + withdraw(user_id); + } + else { + showAllMenuEntries(); + } + } + } + else { + printf("Invalid Input! Please try again.\n"); + withdraw(user_id); + } +} \ No newline at end of file diff --git a/src/withdrawMoney.h b/src/withdrawMoney.h new file mode 100644 index 0000000..f86e618 --- /dev/null +++ b/src/withdrawMoney.h @@ -0,0 +1,6 @@ +#include +#include + +void withdraw(int user_id); +float initiateWithdraw(float amountToWithdraw, float availableAccountBalance); +void notifyCustomer(amountToWithdraw, remainingAccountBalance); \ No newline at end of file