Browse Source

Create function to set saving goal

remotes/origin/feature/balance-operations
fdlt3817 2 years ago
parent
commit
9bf38a1487
  1. 25
      src/interestCalculator.c
  2. 1
      src/interestCalculator.h

25
src/interestCalculator.c

@ -20,6 +20,24 @@ void troubleshoot(int errorCode){
}
}
void askForSavingGoal(float principalAmount, float accInterestPerYear){
char c;
float goal;
float timeForGoal;
printf("\nWould you like to set a saving goal?");
scanf(" %c",&c);
if(c=='y'||c=='Y'){
printf("\nPlease enter your goal amount in €:");
scanf("%f",&goal);
timeForGoal=(goal-principalAmount)/accInterestPerYear;
printf("In %.1f years you will reach your goal of %f.\n", timeForGoal, goal);
}else{
//error
}
}
float initiateInterest(float principalAmount, float interest, float time){
return principalAmount*(1+(interest*time));
}
@ -67,6 +85,7 @@ void calculateYearlyInterest(){
float result= initiateInterest(principalAmount,interestDecimal,timeInYears);
printf("\nAmount with the interest is %.2f€.",result);
askForSavingGoal(principalAmount,principalAmount*interestDecimal);
}
void calculateMonthlyInterest(){
float principalAmount;
@ -123,8 +142,8 @@ void initiateCalculator(){
}
}
// int main(){
int main(){
// initiateCalculator();
initiateCalculator();
// }
}

1
src/interestCalculator.h

@ -5,6 +5,7 @@
void calculateYearlyInterest();
void calculateMonthlyInterest();
void askForSavingGoal(float principalAmount, float accInterestPerYear);
float initiateInterest(float principalAmount, float interest, float time);
void troubleshoot(int errorCode);
#endif
Loading…
Cancel
Save