100-sided dice roll problem When should I stop rolling if it costs $1 for each roll and I earn only the value of the final roll shown on a 100-sided dice roll? My intent is to maximise profit and I have unlimited rolls

First, of all, the only thing that matters as far as deciding when to stop is the last roll. Others have mentioned this without proving it, so here's an argument for it: your winnings depend only on your last roll. You previous rolls don't affect it at all. Furthermore, your marginal cost is not affected by the rolls. You total cost depends on how many previous rolls you had, but optimality is based on marginal cost, not total cost. Since neither cost nor benefit are affected by previous rolls, we can ignore them.
Therefore, whether you should roll again is based solely on what the current roll is. So there are n different strategies: stop as soon as you see a $1$, stop as soon as you see a $2$, etc. If $f(n)$ is the expected winnings for following the nth strategy, then the problem is to find the $n$ that maximizes $f(n)$. So what is $f(n)$? Well, we have a $\frac1{100}$ chance of getting $100$. And if $n<100$, then we have a $\frac1{100}$ chance of getting $99$. And so on. In other words, the expected value after the next roll is $\frac{100+99+98+...n}{100}$. With some knowledge of arithmetic sequences, we can put that in closed form as $\frac 1 {100}*\left(5050-\frac{n(n+1)}2\right)= \frac{10100-n(n+1)}{200} $. There's also a $\frac{n-1}{100}$ chance of not stopping at the next roll, in which case we're right back where we started, except we're down a dollar. So $f(n) = \frac{10100-n(n+1)}{200}+ \frac{(f(n)-1)(n-1)}{100}$.
$$f(n) = \frac{10100-n(n+1)+ 2(f(n)-1)(n-1)}{200}$$
$$200f(n) = 10100-n(n+1)+ 2(f(n)-1)(n-1)$$
$$200f(n) = 10100-n(n+1)+ 2(f(n)(n-1))-n+1$$
$$(200-2n+2)f(n) = 10100-n(n+1)-n+1$$
$$(202-2n)f(n) = 10100-n^2-2n+1$$
$$f(n) = \frac{10101-n^2-2n}{202-2n}$$
This has the maximum value of 84.6176 at n = 85. This isn't the same as previous answers, so I wuite possibly made a mistake with my arithmetic somewhere.
