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:
printf("Invalid option. Aborting.");
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;
float goal;
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);
if(c=='y'||c=='Y'){
printf("\nPlease enter your goal amount in €:");
scanf("%f",&goal);
if(goal>=principalAmount){
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{
//error
troubleshoot(4);
return;
}
}else{
return;
}
}

Loading…
Cancel
Save