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"
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;
}

1
src/interestCalculator.h

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