There is an exact formula for this (or rather, two formulas, one with the "growth value" and one without) which you might be able to deduce from the answer already posted. But here is another way of looking at the problem:
Consider the case where the user opts for a "growth value", since
you can easily deduce the "no growth value" solution by setting the
growth value to zero.
Now observe that the contribution in each successive
year is proportional to the initial amount.
That is, suppose two users try your program, and one enters $P_0 = 100$
and the other enters $P_0 = 200$.
It is easy to see (and not hard to prove) that in each successive year,
the second user's contribution will be exactly twice as much as the
first user's contribution.
(The exact formula is of the form $P_t = P_0 k^t$, where $k$ is a factor determined by the "growth value".)
Furthermore, as you already know, the final value of each year's contribution
is proportional to that year's contribution.
That is $F_y$ (final value for year $y$) is proportional to $P_y$.
But if $F_y$ is proportional to $P_y$, and $P_y$ is proportional to $P_0$,
then $F_y$ is proportional to $P_0$.
Moreover, since this is true for each of the $F_y$ individually, it is also
true for their sum.
So the final total, at the end, will be exactly proportional to $P_0$.
So one way to solve your problem without working out the complete
closed-form equation for the total at the end,
is simply to try the input $P_0 = 1$ and see what total you get at the end.
Then scale this up as needed to achieve the desired total.
For example, suppose that when you set $P_0 = 1$, the sum of all your
$F_y$, that is, your final stock, is $10$.
Then what $P_0$ will produce a final stock of $20$?
What if you want a final stock of $100$, then what should be $P_0$?
The same trick works if you find that the final stock is $15.31456$ when
$P_0 = 1$, and you want to find $P_0$ that will make the final stock be $5000$.
The only difference is that the answer would not be so easy to guess by
mental arithmetic as it was for my first couple of examples.