Question word + TO-infinitive
A question word can be used before a to-infinitive to express an indirect question about what should be done:
We don't know where to put the sofa. (where we should put the sofa)
No one could tell me how to start the engine. (how I should start the engine)
The rules didn't specify who to speak to in case of an emergency. (who you should speak to)
I had no idea what to write my home paper about. (what I should write my home paper about)
Why cannot be used in this way.
If the original question was a yes/no question, we use whether (but not if):
I didn't know whether to laugh or cry. (whether I should laugh or cry)
He couldn't decide whether to accept the job or not. (whether he should accept the job or not)