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.

58 lines
2.0 KiB

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