From c2db120ba7b667f39ffb9ec0904580234a510d1c Mon Sep 17 00:00:00 2001 From: fdlt3817 Date: Thu, 9 Feb 2023 19:09:27 +0100 Subject: [PATCH] Create functionality to do sequential calculations --- src/interestCalculator.c | 55 ++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/src/interestCalculator.c b/src/interestCalculator.c index 9329c2a..67dcd86 100644 --- a/src/interestCalculator.c +++ b/src/interestCalculator.c @@ -2,37 +2,38 @@ void calculateInterest(){ -float principalAmount; -float interestPerYear; -float timeInYears; - -printf("Please enter the principal amount:"); -scanf("%f",&principalAmount); -if(principalAmount<=0){ - return; -} + float principalAmount; + float interestPerYear; + float timeInYears; + + printf("Please enter the principal amount:"); + scanf("%f",&principalAmount); + if(principalAmount<=0){ + return; + } -printf("\nPlease enter interest per year (percentage):"); -scanf("%f",&interestPerYear); -if(interestPerYear<=0){ - return; -} + printf("\nPlease enter interest per year (percentage):"); + scanf("%f",&interestPerYear); + if(interestPerYear<=0){ + return; + } -printf("\nPlease enter interest time in years:"); -scanf("%f",&timeInYears); -if(timeInYears<=0){ - return; -} + printf("\nPlease enter interest time in years:"); + scanf("%f",&timeInYears); + if(timeInYears<=0){ + return; + } -float interestDecimal=interestPerYear/100; + float interestDecimal=interestPerYear/100; -float result= principalAmount*(1+(interestDecimal*timeInYears)); -printf("\nAmount with the interest is %f.",result); + float result= principalAmount*(1+(interestDecimal*timeInYears)); + printf("\nAmount with the interest is %.2f.",result); } void initiateCalculator(){ int input; + char c; printf("Welcome to the interest calculator. Please select an option:\n[1]Calculate yearly interest\n"); scanf("%d", &input); @@ -43,13 +44,17 @@ void initiateCalculator(){ default: break; } - + printf("\nThank you for using our services. Would you like to do another calculation? [y]Yes [any]No\n"); + scanf(" %c", &c); + if(c=='y'||c=='Y'){ + initiateCalculator(); + }else{ + return; + } } -/* int main(){ initiateCalculator(); } -*/ \ No newline at end of file