I can't really pinpoint what's wrong here. This question asks how many years it would take for the investment to double with a given contribution, but with no contribution in year zero. The years output comes up good, but the balance is always off. Thanks in advance for any help, I have trouble with one off errors in loops for some reason.
It works, but there's a lot of duplicated code there. That needlessly clutters the code, and makes it more error-prone. Your code would be better if you re-organized it to avoid that.