Browse Source

Add troubleshoot system to help customers identify problems

remotes/origin/feature/loan-eligibility
fdlt3817 2 years ago
parent
commit
0dce1641d1
  1. 22
      src/interestCalculator.c
  2. 1
      src/interestCalculator.h

22
src/interestCalculator.c

@ -1,6 +1,22 @@
#include "interestCalculator.h" #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(){ void calculateYearlyInterest(){
float principalAmount; float principalAmount;
float interestPerYear; float interestPerYear;
@ -9,18 +25,21 @@ void calculateYearlyInterest(){
printf("Please enter the principal amount:"); printf("Please enter the principal amount:");
scanf("%f",&principalAmount); scanf("%f",&principalAmount);
if(principalAmount<=0){ if(principalAmount<=0){
troubleshoot(0);
return; return;
} }
printf("\nPlease enter interest per year (percentage):"); printf("\nPlease enter interest per year (percentage):");
scanf("%f",&interestPerYear); scanf("%f",&interestPerYear);
if(interestPerYear<=0){ if(interestPerYear<=0){
troubleshoot(1);
return; return;
} }
printf("\nPlease enter interest time in years:"); printf("\nPlease enter interest time in years:");
scanf("%f",&timeInYears); scanf("%f",&timeInYears);
if(timeInYears<=0){ if(timeInYears<=0){
troubleshoot(2);
return; return;
} }
@ -37,18 +56,21 @@ void calculateMonthlyInterest(){
printf("Please enter the principal amount:"); printf("Please enter the principal amount:");
scanf("%f",&principalAmount); scanf("%f",&principalAmount);
if(principalAmount<=0){ if(principalAmount<=0){
troubleshoot(0);
return; return;
} }
printf("\nPlease enter interest per month (percentage):"); printf("\nPlease enter interest per month (percentage):");
scanf("%f",&interestPerMonth); scanf("%f",&interestPerMonth);
if(interestPerMonth<=0){ if(interestPerMonth<=0){
troubleshoot(1);
return; return;
} }
printf("\nPlease enter interest time in months:"); printf("\nPlease enter interest time in months:");
scanf("%f",&timeInMonths); scanf("%f",&timeInMonths);
if(timeInMonths<=0){ if(timeInMonths<=0){
troubleshoot(2);
return; return;
} }

1
src/interestCalculator.h

@ -5,4 +5,5 @@
void calculateYearlyInterest(); void calculateYearlyInterest();
void calculateMonthlyInterest(); void calculateMonthlyInterest();
void troubleshoot(int errorCode);
#endif #endif
Loading…
Cancel
Save