diff --git a/src/interestCalculator.c b/src/interestCalculator.c index 0764a39..58c1072 100644 --- a/src/interestCalculator.c +++ b/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); - timeForGoal=(goal-principalAmount)/accInterestPerYear; - printf("In %.1f years you will reach your goal of %f.\n", timeForGoal, 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{ - //error + return; } }