From cf87508c6b0ca8f5a32b93fd0f182b1c1fa93026 Mon Sep 17 00:00:00 2001 From: fdlt3817 Date: Fri, 10 Feb 2023 16:55:19 +0100 Subject: [PATCH] Hotfix: resolve file name problem (2/2) --- src/currentCustomerAccountBalance.h | 4 +- src/depositMoney.c | 4 +- src/sendMoney.c | 125 ++++++++++++++++++++++++++++ src/sendMoney.h | 14 ++++ src/updateCustomerAccountBalance.h | 4 +- src/withdrawMoney.c | 8 +- 6 files changed, 149 insertions(+), 10 deletions(-) create mode 100644 src/sendMoney.c create mode 100644 src/sendMoney.h diff --git a/src/currentCustomerAccountBalance.h b/src/currentCustomerAccountBalance.h index dc39493..36bb66e 100644 --- a/src/currentCustomerAccountBalance.h +++ b/src/currentCustomerAccountBalance.h @@ -1,5 +1,5 @@ -#ifndef CURRENTCUSTOMERACCOUNTBALANCE_H_ -#define CURRENTCUSTOMERACCOUNTBALANCE_H_ +#ifndef CurrentCustomerAccountBalance_H +#define CurrentCustomerAccountBalance_H #include diff --git a/src/depositMoney.c b/src/depositMoney.c index 33a4e2d..5732f7e 100644 --- a/src/depositMoney.c +++ b/src/depositMoney.c @@ -1,6 +1,6 @@ #include "depositMoney.h" -#include "updateCustomerAccountBalance.c" -#include "currentCustomerAccountBalance.c" +#include "updateCustomerAccountBalance.h" +#include "currentCustomerAccountBalance.h" void askToTryAgain(bool afterError, int customerID){ char choice; diff --git a/src/sendMoney.c b/src/sendMoney.c new file mode 100644 index 0000000..f597ac8 --- /dev/null +++ b/src/sendMoney.c @@ -0,0 +1,125 @@ +#include "sendMoney.h" +#include "depositMoney.h" +#include "withdrawMoney.h" +#include "currencyExchange.h" +#include "currentCustomerAccountBalance.h" +#include "updateCustomerAccountBalance.h" + + + +void showBalance(int customerID){ + float balance=getAvailableAccountBalance(customerID); + printf("\n:.:.:.:.:.:"); + printf("\nYour current balance is %.2f.\n",balance); + printf(":.:.:.:.:.:\n"); +} + +float askToConvert(float input, int customerID){ + char c; + char symbol[]=""; + int id; + float converted; + printf("\nWould you like to convert the amount from € to another currency?[y] yes [any] no\n"); + scanf(" %c",&c); + if(c=='y'||c=='Y'){ + printf("\nPlease select from one of the following currencties to convert to:"); + printf("\n[1] USD"); + printf("\n[2] GBP"); + printf("\n[3] YEN"); + printf("\n[4] YUAN\n"); + scanf("%d",&id); + + if(id>0&&id<5){ + converted=convert(input,id); + }else{ + return 0; + } + switch(id){ + case 1: + symbol[0]='$'; + break; + case 2: + symbol[0]='P'; + break; + case 3: + symbol[0]='Y'; + break; + case 4: + symbol[0]='X'; + break; + } + printf("\nYou have successfuly transfered %.2f%s to [%d]",converted, symbol,customerID); + return converted; + }else{ + return 0; + } +} + +void askToShowBalance(int customerID){ + char c; + printf("\nWould you like to see your remaining balance? [y] yes [any] no\n"); + scanf(" %c",&c); + if(c=='y' || c=='Y'){ + showBalance(customerID); + } + return; +} + +bool sendMoney(int customerID){ + float availableAccountBalance=getAvailableAccountBalance(customerID); + float amountToSend; + int recID; + + showBalance(customerID); + printf("\nHow much would you like to send?\n"); + scanf("%f",&amountToSend); + if(amountToSend>0 && amountToSend1000){ + bool recExists=checkCustomerExists(recID); + if(recExists){ + if(recID==customerID){ + printf("\nYou cannot send money to yourself. Aborting. \n"); + return false; + } + else{ + if(withdrawSpecificAmount(customerID, amountToSend)){ + if(depositSpecificAmount(recID, amountToSend)){ + askToConvert(amountToSend, recID); + //printf("\nYou have successfuly transfered %.2f€ to [%d]",amountToSend,recID); + askToShowBalance(customerID); + return true; + } + else{ + printf("\nSomething went wrong with the transfer. Please contact staff."); + } + } + } + + }else{ + printf("\nThis ID is not from a customer of our bank. A transfer fee of %.2f€ will be taken.\n", TRANSFER_FEE); + if(withdrawSpecificAmount(customerID, amountToSend+TRANSFER_FEE)){ + askToConvert(amountToSend, recID); + //printf("\nYou have successfuly transfered %.2f€ to [%d]\n",amountToSend,recID); + askToShowBalance(customerID); + return true; + } + } + } + else + { + printf("\nThe ID you have entered is not valid. Aborting. \n"); + } + + }else{ + //error + return false; + } + return false; +} + +int main(){ + sendMoney(1234); + return 0; +} \ No newline at end of file diff --git a/src/sendMoney.h b/src/sendMoney.h new file mode 100644 index 0000000..df64387 --- /dev/null +++ b/src/sendMoney.h @@ -0,0 +1,14 @@ +#ifndef SENDMONEY_H +#define SENDMONEY_H +#include +#include +#include +#include + +#define TRANSFER_FEE 0.8 +void showBalance(int customerID); +float askToConvert(float input, int customerID); +void askToShowBalance(int customerID); +bool sendMoney(int customerID); + +#endif // SENDMONEY_H diff --git a/src/updateCustomerAccountBalance.h b/src/updateCustomerAccountBalance.h index 17f34ae..5b056f4 100644 --- a/src/updateCustomerAccountBalance.h +++ b/src/updateCustomerAccountBalance.h @@ -1,5 +1,5 @@ -#ifndef UPDATECUSTOMERACCOUNTBALANCE_H_ -#define UPDATECUSTOMERACCOUNTBALANCE_H_ +#ifndef UpdateCustomerAccountBalance_H +#define UpdateCustomerAccountBalance_H #include #include diff --git a/src/withdrawMoney.c b/src/withdrawMoney.c index 4bd3eaf..65e23b2 100644 --- a/src/withdrawMoney.c +++ b/src/withdrawMoney.c @@ -1,6 +1,7 @@ #include "withdrawMoney.h" -#include "updateCustomerAccountBalance.c" -#include "currentCustomerAccountBalance.c" +#include "updateCustomerAccountBalance.h" +#include "currentCustomerAccountBalance.h" + void notifyCustomer(float amountToWithdraw, float remainingAccountBalance, int user_id) { char c; @@ -51,12 +52,11 @@ bool withdraw(int user_id) { updateSuccess = updateAvailableAccountBalance(user_id, remainingAccountBalance); if( updateSuccess ) { notifyCustomer(amountToWithdraw, remainingAccountBalance, user_id); - return true; } else { printf("Some error occured! Sorry for the inconvenience caused.\n"); - return false; } + return updateSuccess; } else {