From dd623e421903668641bb9022879ac211a9ea5e2d Mon Sep 17 00:00:00 2001 From: fdlt3817 Date: Fri, 10 Feb 2023 14:56:44 +0100 Subject: [PATCH] Implement enter month option to interestCalculator --- src/depositMoney.c | 4 ++-- src/interestCalculator.c | 27 +++++++++++++++++++++++---- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/depositMoney.c b/src/depositMoney.c index 5732f7e..33a4e2d 100644 --- a/src/depositMoney.c +++ b/src/depositMoney.c @@ -1,6 +1,6 @@ #include "depositMoney.h" -#include "updateCustomerAccountBalance.h" -#include "currentCustomerAccountBalance.h" +#include "updateCustomerAccountBalance.c" +#include "currentCustomerAccountBalance.c" void askToTryAgain(bool afterError, int customerID){ char choice; diff --git a/src/interestCalculator.c b/src/interestCalculator.c index d9c2cce..6998887 100644 --- a/src/interestCalculator.c +++ b/src/interestCalculator.c @@ -14,6 +14,9 @@ void troubleshoot(int errorCode){ case 2: printf("Duration not valid. Make sure it is a valid number over the value of zero."); break; + case 3: + printf("Invalid option. Aborting."); + break; } } @@ -25,6 +28,7 @@ void calculateYearlyInterest(){ float principalAmount; float interestPerYear; float timeInYears; + int choice; printf("Please enter the principal amount:"); if (scanf("%f", &principalAmount) != 1 || principalAmount <= 0) { @@ -37,13 +41,28 @@ void calculateYearlyInterest(){ troubleshoot(0); return; } - - printf("\nPlease enter interest time in years:"); - if (scanf("%f", &timeInYears) != 1 || timeInYears <= 0) { + printf("\nWould you like to enter the time in [1]months or in [2]years?\n"); + scanf("%d",&choice); + if(choice==1){ + printf("\nPlease enter interest time in months:"); + if (scanf("%f", &timeInYears) != 1 || timeInYears <= 0) { + troubleshoot(2); + return; + } + timeInYears=timeInYears/12; + + }else if(choice==2){ + printf("\nPlease enter interest time in years:"); + if (scanf("%f", &timeInYears) != 1 || timeInYears <= 0) { + troubleshoot(2); + return; + } + }else{ troubleshoot(2); - return; } + + float interestDecimal=interestPerYear/100; float result= initiateInterest(principalAmount,interestDecimal,timeInYears);