Dan had $ w left with him after he bought a candy bar. If he had $ x at the start How much did the candy bar cost?

Dan had $w left with him after he bought a candy bar. This means that he started with $w+x, and then he spent some of that money on the candy bar. So we can say that:

$w+x - \text{cost of candy bar} = w$

We can solve this equation for the cost of the candy bar:

$\text{cost of candy bar} = w+x-w = x$