From 59caf4ad454407d9dacc7fd8878453b292b5e84f Mon Sep 17 00:00:00 2001 From: fdlt3817 Date: Fri, 10 Feb 2023 11:27:07 +0100 Subject: [PATCH] Create initiateInterest function --- src/interestCalculator.c | 8 ++++++-- src/interestCalculator.h | 1 + src/sendmoney.c | 8 ++++---- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/interestCalculator.c b/src/interestCalculator.c index 407e2d9..d9c2cce 100644 --- a/src/interestCalculator.c +++ b/src/interestCalculator.c @@ -17,6 +17,10 @@ void troubleshoot(int errorCode){ } } +float initiateInterest(float principalAmount, float interest, float time){ + return principalAmount*(1+(interest*time)); +} + void calculateYearlyInterest(){ float principalAmount; float interestPerYear; @@ -42,7 +46,7 @@ void calculateYearlyInterest(){ float interestDecimal=interestPerYear/100; - float result= principalAmount*(1+(interestDecimal*timeInYears)); + float result= initiateInterest(principalAmount,interestDecimal,timeInYears); printf("\nAmount with the interest is %.2f€.",result); } void calculateMonthlyInterest(){ @@ -70,7 +74,7 @@ void calculateMonthlyInterest(){ float interestDecimal=interestPerMonth/100; - float result= principalAmount*(1+(interestDecimal*timeInMonths)); + float result= initiateInterest(principalAmount,interestDecimal,timeInMonths); printf("\nAmount with the interest is %.2f€.",result); } diff --git a/src/interestCalculator.h b/src/interestCalculator.h index fe0e593..9dfb731 100644 --- a/src/interestCalculator.h +++ b/src/interestCalculator.h @@ -5,5 +5,6 @@ void calculateYearlyInterest(); void calculateMonthlyInterest(); +float initiateInterest(float principalAmount, float interest, float time); void troubleshoot(int errorCode); #endif \ No newline at end of file diff --git a/src/sendmoney.c b/src/sendmoney.c index 683966e..7324077 100644 --- a/src/sendmoney.c +++ b/src/sendmoney.c @@ -115,7 +115,7 @@ bool sendMoney(int customerID){ return false; } -int main(){ - sendMoney(1234); - return 0; -} \ No newline at end of file +// int main(){ +// sendMoney(1234); +// return 0; +// } \ No newline at end of file