So what's the big deal...? We all know that 
quoi is the French word for 
what, right?
Well... yes and no.
The French for 
what is generally 
quoi when either:
(a) it's "in situ"-- basically, in a question that keeps its "normal sentence word order":
tu fais quoi demain?
what are you doing tomorrow?
il veut quoi, Jean?
what does Jean want?
qui fait quoi?
who's doing what?
Remember that in everyday spoken French, this type of "in situ" question is generally the most common way of asking a question. In English, you can also form 
in situ questions such as "you're doing WHAT?", but these are normally to express surprise, sarcasm etc. In spoken French, they're often just a normal, neutral way of asking a question.
(b) it's the object of a preposition (
avec, 
de...), either in situ or not:
tu parles de quoi?
de quoi tu parles?
what are you talking about?
je ne sais pas de quoi il parle
I don't know what he's talking about
un livre sur quoi?
a book about what?
ils vont payer avec quoi?
what are they going to pay with?
However, there are places where 
quoi isn't possible:
- if quoi is not in situ (so mainly, a question where either inversion or est-ce que is used);
- and is not the object of a preposition.
In such cases, 
que is used. This generally means that 
what is either the object of the verb, with inversion or 
est-ce que:
que fais-tu?
qu'est-ce que tu fais?
what are you doing?
Or, it means that 
what is the 
subject of the verb. In this case, the formula becomes 
qu'est-ce qui:
qu'est-ce qui pue là?
what stinks round here?, 
="what's that smell?"
what meaning the thing that(s)... (relative clauses)
When 
what is essentially a synonym of 
"the thing(s) that", it is generally translated by either 
ce qui or 
ce que in French. In these cases, we're generally dealing with 
relative clauses, not questions. If it's the 
subject of the verb in the relative clause, then 
ce qui:
ce qui importe le plus, c'est...
what matters most is...
If it's the 
object, then use 
ce que:
Je ne comprends pas ce qu'il a dit
I don't understand what he said
Je ne sais pas ce que font les enfants
I don't know what the children are doing
Ce que tu as dit m'a vraiment énervé
What you said really annoyed me
Now in fact, there are some other possibilities, although they're rarer. This is because the phrase meaning 
the thing that, which introduces the relative clause, could itself be an object of a preposition:
penser à... = 
to think about...
ce à quoi tu penses
what you're thinking about
avoir besoin de... = 
to need...
ce de quoi/dont j'ai besoin
what I need
The expression 
ce dont often replaces 
ce de quoi (and literally means 
the thing about which, 
=the thing of which etc).
In very informal speech, you will sometimes hear sentences such as 
ce que j'ai besoin. However, this construction is generally considered non-standard and would be avoided in more formal speech and writing.
que / quoi as the object of an infinitive
Finally, as an extra complication, both 
que and 
quoi can be the object of an infinitive: so either 
quoi faire? or 
que faire? is possible (although the former is may be a bit more informal).
Which all goes to show that in life and languages, it's often the simple little things that turn out to be complicated...