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?
Let's say that the cost of the candy bar is $c$. 

Then we have the equation: 

$w = x - c$

We need to solve for $c$. 

$c = x - w$

$c = x - (x - w)$

$c = w$