I'm running a simulation that updates in a fixed time $dt$.

I have a car moving straight with initial velocity $v_0$. This car has to move exactly a distance $D$ in $t$ seconds (for simplicity, suppose $t = f \times dt$, where $f$ is an integer).

How can I find the deceleration for the car to stop exactly after traversing $D$?

---

I'm getting confused because if I know the car will stop after $f$ frames, then the deceleration should be $(v_0 \div f)$, but when I do

> for $i = 0, \dots , (f-1):$ 
>
> $\quad$ position = position + speed * dt
> 
> $\quad$ speed = speed - deceleration * dt

The car doesn't stop where it should.