From 17903c5e0cf01184b67b5239b7a80a10f417c7af Mon Sep 17 00:00:00 2001 From: fdlt3817 Date: Thu, 9 Feb 2023 18:42:54 +0100 Subject: [PATCH] Implement interest calculator --- src/interestCalculator.c | 46 ++++++++++++++++++++++++++++++++++++++++ src/interestCalculator.h | 7 ++++++ 2 files changed, 53 insertions(+) create mode 100644 src/interestCalculator.c create mode 100644 src/interestCalculator.h diff --git a/src/interestCalculator.c b/src/interestCalculator.c new file mode 100644 index 0000000..8acc998 --- /dev/null +++ b/src/interestCalculator.c @@ -0,0 +1,46 @@ +#include "interestCalculator.h" + + +void calculateInterest(){ +float principalAmount; +float interestPerYear; +float timeInYears; + +printf("Please enter the principal amount:"); +scanf("%f",&principalAmount); + +printf("\nPlease enter interest per year (percentage):"); +scanf("%f",&interestPerYear); + +printf("\nPlease enter interest time in years:"); +scanf("%f",&timeInYears); + +float interestDecimal=interestPerYear/100; + +float result= principalAmount*(1+(interestDecimal*timeInYears)); +printf("\nAmount with the interest is %f.",result); +} + +void initiateCalculator(){ + + int input; + printf("Welcome to the interest calculator. Please select an option:\n[1]Calculate yearly interest\n"); + scanf("%d", &input); + + switch(input){ + case 1: + calculateInterest(); + break; + default: + break; + } + +} + +/* +int main(){ + + initiateCalculator(); + +} +*/ \ No newline at end of file diff --git a/src/interestCalculator.h b/src/interestCalculator.h new file mode 100644 index 0000000..bd641cd --- /dev/null +++ b/src/interestCalculator.h @@ -0,0 +1,7 @@ +#ifndef INTERESTCALCULATOR_H_ +#define INTERESTCALCULATOR_H_ + +#include + +void calculateInterest(); +#endif \ No newline at end of file