From 0dce1641d1620b0eeac01e0867074cd41a0b216e Mon Sep 17 00:00:00 2001 From: fdlt3817 Date: Thu, 9 Feb 2023 19:23:26 +0100 Subject: [PATCH] Add troubleshoot system to help customers identify problems --- src/interestCalculator.c | 22 ++++++++++++++++++++++ src/interestCalculator.h | 1 + 2 files changed, 23 insertions(+) diff --git a/src/interestCalculator.c b/src/interestCalculator.c index b097ea4..a561d55 100644 --- a/src/interestCalculator.c +++ b/src/interestCalculator.c @@ -1,6 +1,22 @@ #include "interestCalculator.h" +void troubleshoot(int errorCode){ + printf("Error! The requested operation was terminated because of an issue. Here are some details about the error:\n---------------\n"); + + switch(errorCode){ + case 0: + printf("Principal amount not valid. Make sure it is a valid number over the value of zero."); + break; + case 1: + printf("Interest rate not valid. Make sure it is a valid number over the value of zero."); + break; + case 2: + printf("Duration not valid. Make sure it is a valid number over the value of zero."); + break; + } +} + void calculateYearlyInterest(){ float principalAmount; float interestPerYear; @@ -9,18 +25,21 @@ void calculateYearlyInterest(){ printf("Please enter the principal amount:"); scanf("%f",&principalAmount); if(principalAmount<=0){ + troubleshoot(0); return; } printf("\nPlease enter interest per year (percentage):"); scanf("%f",&interestPerYear); if(interestPerYear<=0){ + troubleshoot(1); return; } printf("\nPlease enter interest time in years:"); scanf("%f",&timeInYears); if(timeInYears<=0){ + troubleshoot(2); return; } @@ -37,18 +56,21 @@ void calculateMonthlyInterest(){ printf("Please enter the principal amount:"); scanf("%f",&principalAmount); if(principalAmount<=0){ + troubleshoot(0); return; } printf("\nPlease enter interest per month (percentage):"); scanf("%f",&interestPerMonth); if(interestPerMonth<=0){ + troubleshoot(1); return; } printf("\nPlease enter interest time in months:"); scanf("%f",&timeInMonths); if(timeInMonths<=0){ + troubleshoot(2); return; } diff --git a/src/interestCalculator.h b/src/interestCalculator.h index 171dc12..fe0e593 100644 --- a/src/interestCalculator.h +++ b/src/interestCalculator.h @@ -5,4 +5,5 @@ void calculateYearlyInterest(); void calculateMonthlyInterest(); +void troubleshoot(int errorCode); #endif \ No newline at end of file