In a certain city, a water utility company charges a base fee along with a variable fee based on water consumption. The base fee is $12, and the variable fee is $0.04 per gallon used. One month, a resident notices the total charge on their bill is $40. How many gallons of water did the resident use?