Actually the use of por qué, porque, por que and porqué has its rules and it's not that easy for some people (when writing it).
por qué is used to ask for the reason why (why someone bought the scarf), so the following is right.
¿Por qué compraste la bufanda? -> Why did you buy the scarf?
To ask for how much you should use cuánto
or por cuánto
¿Por cuánto compraste la bufanda? -> For how much did you buy the scarf?
¿Cuánto te (le) costó la bufanda? -> How much did the scarf cost?
¿Cuánto te (le) costó? -> How much was it? or How much did it cost? (After asking why)
About in exchange for what did the person buy it
, in exchange for what
is replaced by a cambio de qué
in most cases. some examples:
in exchange of what did you gave her your pen?
(¿A cambio de qué le diste tu lapicero?)
You may answer:
in exchange of nothing, or in exchange of her eraser.
a cambio de nada, a cambio de su borrador.
in exchange for what can be replaced by por qué to ask the reason why too but in those cases I think you use to use why instead of in exchange for what, and so: ¿por qué le diste tu lapicero? is valid.
To form this question, por and qué are combined to create por qué, the for how much-part of the question. But of course this part is exactly the same as por qué which asks why.
To be conclusve about your specific question:
So how can one ask For how much did you buy the scarf? without asking
Why did you buy the scarf?
¿Cuánto te valió la bufanda?
¿Cuánto te costó la bufanda?
¿Por cuánto compraste la bufanda?
Note: valer, costar mean the same in this case.
(Editions: English grammar.)