Let P = the price of the pizzas and let n = the original number of teenagers. For n teenagers:
P = n*($6)
After 5 teenagers leave (assuming the same total cost, P):
P = (n-5)*($8) = 8n-40
Since the two equations both equal P, set them equal:
6n = 8n - 40
Solve for n