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.

76 lines
2.2 KiB

  1. #include "depositMoney.h"
  2. #include "updateCustomerAccountBalance.h"
  3. #include "currentCustomerAccountBalance.h"
  4. void askToTryAgain(bool afterError, int customerID){
  5. char choice;
  6. printf("\n");
  7. if(afterError){
  8. printf("Would you like to try again? [y] yes [n] no: ");
  9. }else{
  10. printf("Would you like to make another deposit? [y] yes [n] no: ");
  11. }
  12. scanf(" %c", &choice);
  13. switch(choice){
  14. case 'y':
  15. depositMoney(customerID);
  16. break;
  17. case 'n':
  18. break;
  19. }
  20. }
  21. bool depositMoney(int customerID){
  22. float availableAccountBalance=getAvailableAccountBalance(customerID);
  23. if(availableAccountBalance<0){
  24. printf("\nCould not retreive account balance. Please contact staff.\n");
  25. }
  26. float amountToDeposit = 0;
  27. printf("\nPlease enter the amount you want to deposit: ");
  28. scanf("%f", &amountToDeposit);
  29. if(amountToDeposit>=0 && amountToDeposit>MINIMUM_DEPOSIT_AMOUNT){
  30. if(updateAvailableAccountBalance(customerID, availableAccountBalance+amountToDeposit)){
  31. printf("\nYou have successfully deposited %.2f. New account balance is %.2f", amountToDeposit, availableAccountBalance+amountToDeposit);
  32. askToTryAgain(false,customerID);
  33. return true;
  34. }else{
  35. printf("Something went wrong. Please contact staff.");
  36. return false;
  37. }
  38. }else if(amountToDeposit>0){
  39. printf("The amount you entered is lower than the minimum amount.");
  40. askToTryAgain(true,customerID);
  41. return false; //amount lower than minimum deposit amount
  42. }else{
  43. printf("Invalid input.");
  44. askToTryAgain(true,customerID);
  45. return false; //invalid input
  46. }
  47. return false;
  48. }
  49. bool depositSpecificAmount(int customerID, float amount){
  50. float availableAccountBalance=getAvailableAccountBalance(customerID);
  51. if(amount>0){
  52. if(updateAvailableAccountBalance(customerID, availableAccountBalance+amount)){
  53. return true;
  54. }else{
  55. return false;
  56. }
  57. }
  58. return false;
  59. }
  60. /*
  61. int main(){
  62. depositSpecificAmount(1234,5000);
  63. //depositMoney(1234);
  64. return 0;
  65. }
  66. */