From 06d8bef1f1be11570acbbc31ec11474636faef6b Mon Sep 17 00:00:00 2001 From: fdlt3817 Date: Wed, 25 Jan 2023 15:02:45 +0100 Subject: [PATCH] Created "Try Again" loop and added minimum deposit amount --- src/depositMoney.c | 46 +++++++++++++++++++++++++++++++++++----------- src/depositMoney.h | 9 +++++++-- 2 files changed, 42 insertions(+), 13 deletions(-) diff --git a/src/depositMoney.c b/src/depositMoney.c index 1252104..67c9012 100644 --- a/src/depositMoney.c +++ b/src/depositMoney.c @@ -1,9 +1,26 @@ -#include "depositMoney.h" +#include "DepositMoney.h" - - - -int InitiateDepositMoney(float amountToDeposit, float availableAccountBalance){ //type of int to return possible end cases. +void AskToTryAgain(bool afterError){ + 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: "); + } + scanf(" %c", &choice); + switch(choice){ + case 'y': + DepositMoney(); + break; + case 'n': + break; + } + +} +int InitiateDepositMoney(float amountToDeposit, float availableAccountBalance){ //type of int to returnpossible end cases. + + return 1; } @@ -11,16 +28,23 @@ int DepositMoney(){ //TODO: Set a minimum deposit amount. float amountToDeposit; float availableAccountBalance = 10000; //for testing purposes. will be replaced with an actual function to retrieve this data. - - printf("Please enter the amount to deposit: "); + + printf("\nPlease enter the amount to deposit: "); scanf("%f", &amountToDeposit); - if(amountToDeposit>0){ + if(amountToDeposit>0 && amountToDeposit>MINIMUM_DEPOSIT_AMOUNT){ //InitiateDepositMoney(amountToDeposit,availableAccountBalance); - printf("You have successfully deposited %f. New account balance is %f", amountToDeposit, availableAccountBalance+amountToDeposit); + printf("You have successfully deposited %.2f. New account balance is %.2f", amountToDeposit, availableAccountBalance+amountToDeposit); + AskToTryAgain(false); return 0; + }else if(amountToDeposit>0){ + printf("The amount you entered is lower than the minimum amount."); + AskToTryAgain(true); + return 1; //amount lower than minimum deposit amount }else{ - return 1; //invalid input + printf("Invalid input."); + AskToTryAgain(true); + return 2; //invalid input } } @@ -29,4 +53,4 @@ int main() char any; DepositMoney(); scanf("%c", &any); -} \ No newline at end of file +} diff --git a/src/depositMoney.h b/src/depositMoney.h index 1ebb776..b6a09ec 100644 --- a/src/depositMoney.h +++ b/src/depositMoney.h @@ -1,4 +1,9 @@ #include -#include +#include "CustomerProperties.h" +#include +#define MINIMUM_DEPOSIT_AMOUNT 5 + + int InitiateDepositMoney(float amountToDeposit, float availableAccountBalance); -int DepositMoney(); \ No newline at end of file +int DepositMoney(); +void AskToTryAgain(bool afterError);