There are several ways to solve this. First, you can divide $18 by 6, which is $3, to find the price for one gallon, then multiply this by 8 (so the total would be $24).
Or, you can use this less conventional and more complicated method to try to impress your teachers with how smart you are: Multiply the price for 6 gallons by 4, to find the price for 24 gallons ($18*4=$72), then divide it by 3 (since 8*3=24) to find the price for 8 gallons. This is $72/3=$24.