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.

60 lines
2.1 KiB

  1. #include "withdrawMoney.h"
  2. #include "currentCustomerAccountBalance.c"
  3. #include "updateCustomerAccountBalance.c"
  4. void notifyCustomer(float amountToWithdraw, float remainingAccountBalance) {
  5. char returnToHomeInput;
  6. printf("You have successfully withdrawn %f €.\n", amountToWithdraw);
  7. printf("Remaining account balance: %f €\n\n", remainingAccountBalance);
  8. printf("Press any key to return to home page: ");
  9. scanf("%c", &returnToHomeInput);
  10. if (returnToHomeInput) {
  11. //showAllMenuEntries();
  12. }
  13. }
  14. float initiateWithdraw(float amountToWithdraw, float availableAccountBalance) {
  15. float remainingAccountBalance = (availableAccountBalance - amountToWithdraw);
  16. return remainingAccountBalance;
  17. }
  18. void withdraw(int user_id) {
  19. float amountToWithdraw;
  20. char tryDifferentAmount;
  21. float remainingAccountBalance;
  22. bool updateSuccess = false;
  23. printf("Enter amount to withdraw: ");
  24. scanf("%f", &amountToWithdraw);
  25. float availableAccountBalance = getAvailableAccountBalance(user_id);
  26. if (amountToWithdraw > 0) {
  27. if (amountToWithdraw <= availableAccountBalance) {
  28. remainingAccountBalance = initiateWithdraw(amountToWithdraw, availableAccountBalance);
  29. updateSuccess = updateAvailableAccountBalance(user_id, remainingAccountBalance);
  30. if( updateSuccess ) {
  31. notifyCustomer(amountToWithdraw, remainingAccountBalance);
  32. }
  33. else {
  34. printf("Some error occured! Sorry for the inconvenience caused.\n");
  35. }
  36. }
  37. else {
  38. printf("You don't have sufficient money to withdraw. Do you want to try different amount?\n[y]: Yes, any other key : exit");
  39. scanf("%c", &tryDifferentAmount);
  40. if (tryDifferentAmount == 'Y' || tryDifferentAmount == 'y') {
  41. withdraw(user_id);
  42. }
  43. else {
  44. //showAllMenuEntries();
  45. }
  46. }
  47. }
  48. else {
  49. printf("Invalid Input! Please try again.\n");
  50. withdraw(user_id);
  51. }
  52. }