From 48b95447a10951cd5a7d5b061ed6cc97d863531e Mon Sep 17 00:00:00 2001 From: Shivam Chaudhary Date: Tue, 24 Jan 2023 20:48:50 +0100 Subject: [PATCH] Create withdrawMoney.c to implement 'withdraw' function --- src/withdrawMoney.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/withdrawMoney.c diff --git a/src/withdrawMoney.c b/src/withdrawMoney.c new file mode 100644 index 0000000..dc3a2e9 --- /dev/null +++ b/src/withdrawMoney.c @@ -0,0 +1,30 @@ +#include + +void withdraw() { + float amountToWithdraw; + char tryDifferentAmount; + + float availableAccountBalance = getAvailableAccountBalance(); + + printf("Enter amount to withdraw: "); + scanf("%f", &amountToWithdraw); + if (amountToWithdraw > 0) { + if (amountToWithdraw <= availableAccountBalance) { + initiateWithdraw(amountToWithdraw, availableAccountBalance); + } + 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(); + } + else { + // return to home page + } + } + } + else { + printf("Invalid Input! Please try again.\n"); + withdraw(); + } +} \ No newline at end of file