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