From 714b7cbc6a135eba24f04f62bf5b5bae48208f66 Mon Sep 17 00:00:00 2001 From: fdlt3817 Date: Thu, 9 Feb 2023 19:04:32 +0100 Subject: [PATCH] Improve interest calculator to check for invalid inputs --- src/interestCalculator.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/interestCalculator.c b/src/interestCalculator.c index 8acc998..9329c2a 100644 --- a/src/interestCalculator.c +++ b/src/interestCalculator.c @@ -8,12 +8,21 @@ 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 time in years:"); scanf("%f",&timeInYears); +if(timeInYears<=0){ + return; +} float interestDecimal=interestPerYear/100;