Browse Source

Refactoring: optimize saving request

remotes/origin/feature/balance-operations
fdlt3817 2 years ago
parent
commit
28b1b195cb
  1. 20
      src/interestCalculator.c

20
src/interestCalculator.c

@ -27,25 +27,27 @@ void askForSavingGoal(float principalAmount, float accInterestPerYear){
char c;
float goal;
float timeForGoal;
printf("\nWould you like to set a saving goal? [y] yes [any] no");
printf("\nWould you like to set a saving goal? [y/n]: ");
scanf(" %c", &c);
if(c=='y'||c=='Y'){
if (c != 'y' && c != 'Y') {
return;
}
printf("\nPlease enter your goal amount in €: ");
scanf("%f", &goal);
if(goal>=principalAmount){
timeForGoal=(goal-principalAmount)/accInterestPerYear;
printf("\nIn %.1f years you will reach your goal of %f.\n", timeForGoal, goal);
}else{
if (goal < principalAmount) {
troubleshoot(4);
return;
}
}else{
return;
}
timeForGoal = (goal - principalAmount) / accInterestPerYear;
printf("\nIn %.1f years you will reach your goal of %.2f.\n", timeForGoal, goal);
}
float initiateInterest(float principalAmount, float interest, float time){
return principalAmount*(1+(interest*time));
}

Loading…
Cancel
Save