Let's say Dan started out with b comic books.
He sold half of the, leaving (1/2)b books.
He then bought 8 more, so that he owned (1/2)b + 8 books, or 12 books.
Solve for b: Subtract 8 books from both sides, obtaining (1/2)b = 4 books.
Multiplying both sides by 2, to clear the fraction, we get b = 8 books.
Dan started out with 8 books.
He sold half, leaving himself with 4 books.
Then he bought 8 more. 4 plus 8 is 12, which checks with the problem statement.