From de0cca7f9ef6691512103f52241caecd9672c93a Mon Sep 17 00:00:00 2001
From: fdlt3817 <can.hacioglu@lt.hs-fulda.de>
Date: Fri, 10 Feb 2023 21:48:37 +0100
Subject: [PATCH] Refactoring depositMoney

---
 src/depositMoney.c | 50 ++++++++++++++++++++++++----------------------
 1 file changed, 26 insertions(+), 24 deletions(-)

diff --git a/src/depositMoney.c b/src/depositMoney.c
index 5732f7e..5ef5a25 100644
--- a/src/depositMoney.c
+++ b/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.");
-            return false;
-        }
-    }else if(amountToDeposit>0){
-        printf("The amount you entered is lower than the minimum amount.");
-        askToTryAgain(true,customerID);
-        return false; //amount lower than minimum deposit amount
-    }else{
+    if (amountToDeposit < 0) {
         printf("Invalid input.");
-        askToTryAgain(true,customerID);
-        return false; //invalid input
+        askToTryAgain(true, customerID);
+        return false;
+    }
+    else if (amountToDeposit < MINIMUM_DEPOSIT_AMOUNT) {
+        printf("The amount you entered is lower than the minimum amount.");
+        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;
     }
-    return false;
 }
 
+
 bool depositSpecificAmount(int customerID, float amount){
 
     float availableAccountBalance=getAvailableAccountBalance(customerID);
@@ -74,4 +76,4 @@ int main(){
     //depositMoney(1234);
     return 0;
 }
-*/
\ No newline at end of file
+*/