Multiply the start price ($31.50) by the tax rate (.09) to get how much tax will be added to the start price.
31.50 x .09 = 2.835 or about 2.84
Tax = $2.84
New total = $34.34
Multiply the new total ($34.34) by the planned tip (.18) to get how much you will tip in addition to the new total.
34.34 x .18 = 6.1812 or about 6.18
Tip = $6.18
Final total = $40.52