Browse Source

Prevent unlogical calculations

remotes/origin/feature/balance-operations
fdlt3817 2 years ago
parent
commit
8ef7a2647f
  1. 14
      src/interestCalculator.c

14
src/interestCalculator.c

@ -17,6 +17,9 @@ void troubleshoot(int errorCode){
case 3: case 3:
printf("Invalid option. Aborting."); printf("Invalid option. Aborting.");
break; break;
case 4:
printf("Your goal cannot be smaller than your principal funds. Aborting.");
break;
} }
} }
@ -24,16 +27,21 @@ void askForSavingGoal(float principalAmount, float accInterestPerYear){
char c; char c;
float goal; float goal;
float timeForGoal; float timeForGoal;
printf("\nWould you like to set a saving goal?");
printf("\nWould you like to set a saving goal? [y] yes [any] no");
scanf(" %c",&c); scanf(" %c",&c);
if(c=='y'||c=='Y'){ if(c=='y'||c=='Y'){
printf("\nPlease enter your goal amount in €:"); printf("\nPlease enter your goal amount in €:");
scanf("%f",&goal); scanf("%f",&goal);
if(goal>=principalAmount){
timeForGoal=(goal-principalAmount)/accInterestPerYear; timeForGoal=(goal-principalAmount)/accInterestPerYear;
printf("In %.1f years you will reach your goal of %f.\n", timeForGoal, goal);
printf("\nIn %.1f years you will reach your goal of %f.\n", timeForGoal, goal);
}else{ }else{
//error
troubleshoot(4);
return;
}
}else{
return;
} }
} }

Loading…
Cancel
Save