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 had some amount of money before he bought the candy bar, we'll call this $x. 

We also know that after he bought the candy bar, he had $w left. 

This means that the cost of the candy bar was $x - $w.