Browse Source

Add missing parameter to function and organise code

remotes/origin/feature/withdraw-money-system
Shivam Chaudhary 2 years ago
parent
commit
57a64876be
  1. 23
      src/withdrawMoney.c

23
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");

Loading…
Cancel
Save