From 2d7332c63387d9a526ae0aa02560b9096989f24b Mon Sep 17 00:00:00 2001 From: fdlt3817 Date: Fri, 10 Feb 2023 21:49:52 +0100 Subject: [PATCH] Refactor sendMoney --- src/sendMoney.c | 88 ++++++++++++++++++++++--------------------------- 1 file changed, 40 insertions(+), 48 deletions(-) diff --git a/src/sendMoney.c b/src/sendMoney.c index 191dca0..63fdf95 100644 --- a/src/sendMoney.c +++ b/src/sendMoney.c @@ -64,57 +64,49 @@ void askToShowBalance(int customerID){ } return; } +bool sendMoney(int customerID) { + float available_account_balance = getAvailableAccountBalance(customerID); + float amount_to_send; + int recipient_id; -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; - } + showBalance(customerID); + printf("\nHow much would you like to send?\n"); + scanf("%f", &amount_to_send); + if (amount_to_send > 0 && amount_to_send < available_account_balance) { + printf("\nYour input was %.2f€. Please enter the recipient id.\n", amount_to_send); + scanf("%d", &recipient_id); + if (recipient_id > 1000) { + bool recipient_exists = checkCustomerExists(recipient_id); + if (recipient_exists) { + if (recipient_id == customerID) { + printf("\nYou cannot send money to yourself. Aborting. \n"); + return false; + } else { + if (withdrawSpecificAmount(customerID, amount_to_send)) { + if (depositSpecificAmount(recipient_id, amount_to_send)) { + askToConvert(amount_to_send, recipient_id); + askToShowBalance(customerID); + return true; + } else { + printf("\nSomething went wrong with the transfer. Please contact staff."); } + } } - else - { - printf("\nThe ID you have entered is not valid. Aborting. \n"); + } 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, amount_to_send + TRANSFER_FEE)) { + askToConvert(amount_to_send, recipient_id); + askToShowBalance(customerID); + return true; } - - }else{ - //error - return false; + } + } else { + printf("\nThe ID you have entered is not valid. Aborting. \n"); } + } else { + // error return false; -} \ No newline at end of file + } + return false; +} +