Last active
January 1, 2016 11:49
-
-
Save mhoran/8140818 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int yearsToRetirementHelper(float principal, float rateOfReturn, float annualPostTaxIncome, float annualExpenses, int yearsToRetirementAcc) { | |
float returnOnInvestment = principal * rateOfReturn; | |
if (returnOnInvestment > annualExpenses) { | |
return yearsToRetirementAcc; | |
} else { | |
float newStash = (principal + returnOnInvestment + annualPostTaxIncome) - annualExpenses; | |
return yearsToRetirementHelper(newStash, rateOfReturn, annualPostTaxIncome, annualExpenses, yearsToRetirementAcc + 1); | |
} | |
} | |
int yearsToRetirement(float principal, float rateOfReturn, float annualPostTaxIncome, float annualExpenses) { | |
return yearsToRetirementHelper(principal, rateOfReturn, annualPostTaxIncome, annualExpenses, 0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment