Flip a coin, but you lose when tails appears
You have to calculate the expected value of continuing. Suppose you have $x$ dollars in earnings, if you continue you can expect to earn $1000$ dollars at chance $p$ and lose $x$ dollars at chance $(1-p)$, so your expected earnings are $1000p-(1-p)x$. If this is value is positive carry on, if it is not quit. In this case this means you should stop if $x\geq 1000\frac{p}{1-p}$.