From 400b3be6686c0ece919374c8f16c407572cdcb6c Mon Sep 17 00:00:00 2001 From: fdlt3817 Date: Thu, 9 Feb 2023 22:58:08 +0100 Subject: [PATCH] Prevent user from sending money to themselves --- src/sendmoney.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/sendmoney.c b/src/sendmoney.c index 930f954..0980976 100644 --- a/src/sendmoney.c +++ b/src/sendmoney.c @@ -14,14 +14,22 @@ bool sendMoney(int customerID){ if(recID>1000){ bool recExists=checkCustomerExists(recID); if(recExists){ - if(withdrawSpecificAmount(customerID, amountToSend)){ - if(depositSpecificAmount(recID, amountToSend)){ - printf("\nYou have successfuly transfered %.2f€ to [%d]",amountToSend,recID); - return true; + if(recID==customerID){ + printf("\nYou cannot send money to yourself. Aborting. \n"); + return false; + } + else{ + if(withdrawSpecificAmount(customerID, amountToSend)){ + if(depositSpecificAmount(recID, amountToSend)){ + printf("\nYou have successfuly transfered %.2f€ to [%d]",amountToSend,recID); + return true; + } + else{ + printf("\nSomething went wrong with the transfer. Please contact staff."); + } } - }else{ - printf("\nSomething went wrong with the transfer. Please contact staff."); } + }else{ if(withdrawSpecificAmount(customerID, amountToSend)){ printf("\nYou have successfuly transfered %.2f€ to [%d]",amountToSend,recID);