Browse Source

Merge branch 'feature/withdraw-money-system' into feature/balance-operations

remotes/origin/feature/transfer-money
Shivam Chaudhary 2 years ago
parent
commit
a76cb12cb2
  1. 59
      src/withdrawMoney.c
  2. 6
      src/withdrawMoney.h

59
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);
}
}

6
src/withdrawMoney.h

@ -0,0 +1,6 @@
#include <stdio.h>
#include <stdbool.h>
void withdraw(int user_id);
float initiateWithdraw(float amountToWithdraw, float availableAccountBalance);
void notifyCustomer(amountToWithdraw, remainingAccountBalance);
Loading…
Cancel
Save