Browse Source

Refactoring depositMoney 2

remotes/origin/Alpha
fdlt3817 2 years ago
parent
commit
13b6c81c52
  1. 24
      src/depositMoney.c

24
src/depositMoney.c

@ -3,23 +3,15 @@
#include "currentCustomerAccountBalance.h" #include "currentCustomerAccountBalance.h"
void askToTryAgain(bool afterError, int customerID){ void askToTryAgain(bool afterError, int customerID){
char choice;
printf("\n"); printf("\n");
if(afterError){
printf("Would you like to try again? [y] yes [n] no: ");
}else{
printf("Would you like to make another deposit? [y] yes [n] no: ");
}
char choice;
printf("%s [y] yes [n] no: ", afterError ? "Would you like to try again?" : "Would you like to make another deposit?");
scanf(" %c", &choice); scanf(" %c", &choice);
switch(choice){
case 'y':
depositMoney(customerID);
break;
case 'n':
break;
if (choice == 'y') {
depositMoney(customerID);
} }
} }
bool depositMoney(int customerID){ bool depositMoney(int customerID){
@ -34,12 +26,12 @@ bool depositMoney(int customerID){
scanf("%f", &amountToDeposit); scanf("%f", &amountToDeposit);
if (amountToDeposit < 0) { if (amountToDeposit < 0) {
printf("Invalid input.");
printf("\nInvalid input.");
askToTryAgain(true, customerID); askToTryAgain(true, customerID);
return false; return false;
} }
else if (amountToDeposit < MINIMUM_DEPOSIT_AMOUNT) { else if (amountToDeposit < MINIMUM_DEPOSIT_AMOUNT) {
printf("The amount you entered is lower than the minimum amount.");
printf("\nThe amount you entered is lower than the minimum amount.");
askToTryAgain(true, customerID); askToTryAgain(true, customerID);
return false; return false;
} }
@ -50,7 +42,7 @@ bool depositMoney(int customerID){
return true; return true;
} }
else { else {
printf("Something went wrong. Please contact staff.");
printf("\nSomething went wrong. Please contact staff.");
return false; return false;
} }
} }

Loading…
Cancel
Save