For 31 days, he needs 40 cans of dog food.
[tex]\begin{gathered} 31\text{ days}=40\text{ cans} \\ 1\text{ day}=\frac{40}{31}\text{ cans} \\ 6\text{ days}=\frac{40}{31}\times6 \\ =7.74\text{ cans} \end{gathered}[/tex]Thus, he should buy 8 cans for 6 days.