From 13b6c81c526e6e9f6c297b997a5abac1b6892b5b Mon Sep 17 00:00:00 2001 From: fdlt3817 Date: Fri, 10 Feb 2023 21:49:23 +0100 Subject: [PATCH] Refactoring depositMoney 2 --- src/depositMoney.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/src/depositMoney.c b/src/depositMoney.c index 5ef5a25..21587c2 100644 --- a/src/depositMoney.c +++ b/src/depositMoney.c @@ -3,23 +3,15 @@ #include "currentCustomerAccountBalance.h" void askToTryAgain(bool afterError, int customerID){ - char choice; - 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); - switch(choice){ - case 'y': - depositMoney(customerID); - break; - case 'n': - break; + if (choice == 'y') { + depositMoney(customerID); } + } bool depositMoney(int customerID){ @@ -34,12 +26,12 @@ bool depositMoney(int customerID){ scanf("%f", &amountToDeposit); if (amountToDeposit < 0) { - printf("Invalid input."); + printf("\nInvalid input."); askToTryAgain(true, customerID); return false; } 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); return false; } @@ -50,7 +42,7 @@ bool depositMoney(int customerID){ return true; } else { - printf("Something went wrong. Please contact staff."); + printf("\nSomething went wrong. Please contact staff."); return false; } }