Quick answer
pedir = to ask for something, to order.
preguntar = to ask a question.
Side by side
Le pedí un café.I asked him for a coffee.
Le pregunté por el café.I asked him about the coffee.
Memory trick
If a thing could arrive on a tray, it is pedir. If the answer is words, it is preguntar.
Typical mistakes
Pregunté un café.
Pedí un café.
You want the coffee, not information about it.
Pedí dónde está el baño.
Pregunté dónde está el baño.
That is a question, so preguntar.
Check yourself
Voy a ___ la cuenta.