Browse Source

Refactoring depositMoney

remotes/origin/Alpha
fdlt3817 2 years ago
parent
commit
de0cca7f9e
  1. 40
      src/depositMoney.c

40
src/depositMoney.c

@ -23,37 +23,39 @@ void askToTryAgain(bool afterError, int customerID){
}
bool depositMoney(int customerID){
float availableAccountBalance=getAvailableAccountBalance(customerID);
if(availableAccountBalance<0){
printf("\nCould not retreive account balance. Please contact staff.\n");
float availableAccountBalance = getAvailableAccountBalance(customerID);
if (availableAccountBalance < 0) {
printf("\nCould not retrieve account balance. Please contact staff.\n");
return false;
}
float amountToDeposit = 0;
printf("\nPlease enter the amount you want to deposit: ");
float amountToDeposit = 0;
scanf("%f", &amountToDeposit);
if(amountToDeposit>=0 && amountToDeposit>MINIMUM_DEPOSIT_AMOUNT){
if(updateAvailableAccountBalance(customerID, availableAccountBalance+amountToDeposit)){
printf("\nYou have successfully deposited %.2f. New account balance is %.2f", amountToDeposit, availableAccountBalance+amountToDeposit);
askToTryAgain(false,customerID);
return true;
}else{
printf("Something went wrong. Please contact staff.");
if (amountToDeposit < 0) {
printf("Invalid input.");
askToTryAgain(true, customerID);
return false;
}
}else if(amountToDeposit>0){
else if (amountToDeposit < MINIMUM_DEPOSIT_AMOUNT) {
printf("The amount you entered is lower than the minimum amount.");
askToTryAgain(true,customerID);
return false; //amount lower than minimum deposit amount
}else{
printf("Invalid input.");
askToTryAgain(true,customerID);
return false; //invalid input
askToTryAgain(true, customerID);
return false;
}
if (updateAvailableAccountBalance(customerID, availableAccountBalance + amountToDeposit)) {
printf("\nYou have successfully deposited %.2f. New account balance is %.2f", amountToDeposit, availableAccountBalance + amountToDeposit);
askToTryAgain(false, customerID);
return true;
}
else {
printf("Something went wrong. Please contact staff.");
return false;
}
}
bool depositSpecificAmount(int customerID, float amount){
float availableAccountBalance=getAvailableAccountBalance(customerID);

Loading…
Cancel
Save