.
If you read the condition ATTENTIVELY, you IMMEDIATELY will see that
the difference in their buyings is 6 - 2 = 4 hats, and the difference in their spendings is 62 - 34 = 28.
Hence, one hat price is 28/4 = 7 dollars.
From this point, YOU do the rest ON YOUR OWN.
Learn on how to solve such problems M E N T A L L Y.
This problem is designed and destined to be solved mentally;
it is the main reason why it was created and why it was given to you.
---------------
To see many other similar problems solved, look into the lesson
- Solving mentally word problems on two equations in two unknowns
in this site.
Also, you have this free of charge online textbook in ALGEBRA-I in this site
- ALGEBRA-I - YOUR ONLINE TEXTBOOK.
The referred lesson is the part of this online textbook under the topic "Systems of two linear equations in two unknowns".
Save the link to this online textbook together with its description
Free of charge online textbook in ALGEBRA-I
https://www.algebra.com/algebra/homework/quadratic/lessons/ALGEBRA-I-YOUR-ONLINE-TEXTBOOK.lesson
to your archive and use it when it is needed.