Browse Source

Created "Try Again" loop and added minimum deposit amount

remotes/origin/feature/deposit-system
fdlt3817 2 years ago
parent
commit
06d8bef1f1
  1. 46
      src/depositMoney.c
  2. 9
      src/depositMoney.h

46
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; return 1;
} }
@ -11,16 +28,23 @@ int DepositMoney(){
//TODO: Set a minimum deposit amount. //TODO: Set a minimum deposit amount.
float amountToDeposit; float amountToDeposit;
float availableAccountBalance = 10000; //for testing purposes. will be replaced with an actual function to retrieve this data. 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); scanf("%f", &amountToDeposit);
if(amountToDeposit>0){
if(amountToDeposit>0 && amountToDeposit>MINIMUM_DEPOSIT_AMOUNT){
//InitiateDepositMoney(amountToDeposit,availableAccountBalance); //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; 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{ }else{
return 1; //invalid input
printf("Invalid input.");
AskToTryAgain(true);
return 2; //invalid input
} }
} }
@ -29,4 +53,4 @@ int main()
char any; char any;
DepositMoney(); DepositMoney();
scanf("%c", &any); scanf("%c", &any);
}
}

9
src/depositMoney.h

@ -1,4 +1,9 @@
#include <stdio.h> #include <stdio.h>
#include <conio.h>
#include "CustomerProperties.h"
#include <stdbool.h>
#define MINIMUM_DEPOSIT_AMOUNT 5
int InitiateDepositMoney(float amountToDeposit, float availableAccountBalance); int InitiateDepositMoney(float amountToDeposit, float availableAccountBalance);
int DepositMoney();
int DepositMoney();
void AskToTryAgain(bool afterError);
Loading…
Cancel
Save