Let x be the number of gallons you buy. Since each gallon cost $2.35 then the total cost of the gas would be:

To this we have to add the car wash, then we have:

Since we have $40 dollars we equate the expression above to this amount to find how many gallons we can buy:

Solving for x we have:

Assuming we can only buy exact gallons you can buy 14 gallons.