Browse Source

Refactoring: optimize saving request

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

32
src/interestCalculator.c

@ -23,29 +23,31 @@ void troubleshoot(int errorCode){
}
}
void askForSavingGoal(float principalAmount, float accInterestPerYear){
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");
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("\nIn %.1f years you will reach your goal of %f.\n", timeForGoal, goal);
}else{
troubleshoot(4);
return;
}
}else{
printf("\nWould you like to set a saving goal? [y/n]: ");
scanf(" %c", &c);
if (c != 'y' && c != 'Y') {
return;
}
printf("\nPlease enter your goal amount in €: ");
scanf("%f", &goal);
if (goal < principalAmount) {
troubleshoot(4);
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