Browse Source

Create functionality to do sequential calculations

remotes/origin/feature/loan-eligibility
fdlt3817 2 years ago
parent
commit
c2db120ba7
  1. 47
      src/interestCalculator.c

47
src/interestCalculator.c

@ -2,37 +2,38 @@
void calculateInterest(){ void calculateInterest(){
float principalAmount;
float interestPerYear;
float timeInYears;
float principalAmount;
float interestPerYear;
float timeInYears;
printf("Please enter the principal amount:");
scanf("%f",&principalAmount);
if(principalAmount<=0){
printf("Please enter the principal amount:");
scanf("%f",&principalAmount);
if(principalAmount<=0){
return; return;
}
}
printf("\nPlease enter interest per year (percentage):");
scanf("%f",&interestPerYear);
if(interestPerYear<=0){
printf("\nPlease enter interest per year (percentage):");
scanf("%f",&interestPerYear);
if(interestPerYear<=0){
return; return;
}
}
printf("\nPlease enter interest time in years:");
scanf("%f",&timeInYears);
if(timeInYears<=0){
printf("\nPlease enter interest time in years:");
scanf("%f",&timeInYears);
if(timeInYears<=0){
return; return;
}
}
float interestDecimal=interestPerYear/100;
float interestDecimal=interestPerYear/100;
float result= principalAmount*(1+(interestDecimal*timeInYears));
printf("\nAmount with the interest is %f.",result);
float result= principalAmount*(1+(interestDecimal*timeInYears));
printf("\nAmount with the interest is %.2f.",result);
} }
void initiateCalculator(){ void initiateCalculator(){
int input; int input;
char c;
printf("Welcome to the interest calculator. Please select an option:\n[1]Calculate yearly interest\n"); printf("Welcome to the interest calculator. Please select an option:\n[1]Calculate yearly interest\n");
scanf("%d", &input); scanf("%d", &input);
@ -43,13 +44,17 @@ void initiateCalculator(){
default: default:
break; break;
} }
printf("\nThank you for using our services. Would you like to do another calculation? [y]Yes [any]No\n");
scanf(" %c", &c);
if(c=='y'||c=='Y'){
initiateCalculator();
}else{
return;
}
} }
/*
int main(){ int main(){
initiateCalculator(); initiateCalculator();
} }
*/
Loading…
Cancel
Save