From the given, we can setup an equation given by the two equations:
(1) Number of hats on Monday, x, and 5 new hats bought on Tuesday is equal to total number of hats, h
x+5 =h
(2) Half of the hats is equal to 17
\frac{1}{2}h=17
We can get x by substituting equation (1) into (2):
\frac{1}{2}\left(x+5\right)=17\xrightarrow{}x+5=34\xrightarrow{}x=34-5=29
Answer: 29 hats on Monday