You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

61 lines
2.1 KiB

#include "withdrawMoney.h"
#include "currentCustomerAccountBalance.c"
#include "updateCustomerAccountBalance.c"
void notifyCustomer(float amountToWithdraw, float remainingAccountBalance) {
char returnToHomeInput;
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 = updateAvailableAccountBalance(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);
}
}