You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
77 lines
2.2 KiB
77 lines
2.2 KiB
#include "depositMoney.h"
|
|
#include "updateCustomerAccountBalance.h"
|
|
#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: ");
|
|
}
|
|
scanf(" %c", &choice);
|
|
switch(choice){
|
|
case 'y':
|
|
depositMoney(customerID);
|
|
break;
|
|
case 'n':
|
|
break;
|
|
}
|
|
|
|
}
|
|
|
|
bool depositMoney(int customerID){
|
|
|
|
float availableAccountBalance=getAvailableAccountBalance(customerID);
|
|
if(availableAccountBalance<0){
|
|
printf("\nCould not retreive account balance. Please contact staff.\n");
|
|
}
|
|
float amountToDeposit = 0;
|
|
|
|
printf("\nPlease enter the amount you want to deposit: ");
|
|
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{
|
|
printf("Invalid input.");
|
|
askToTryAgain(true,customerID);
|
|
return false; //invalid input
|
|
}
|
|
return false;
|
|
}
|
|
|
|
bool depositSpecificAmount(int customerID, float amount){
|
|
|
|
float availableAccountBalance=getAvailableAccountBalance(customerID);
|
|
|
|
if(amount>0){
|
|
if(updateAvailableAccountBalance(customerID, availableAccountBalance+amount)){
|
|
return true;
|
|
}else{
|
|
return false;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/*
|
|
int main(){
|
|
depositSpecificAmount(1234,5000);
|
|
//depositMoney(1234);
|
|
return 0;
|
|
}
|
|
*/
|