I can not explain it, but both "I don't have anything to eat" or " Did you have to say that?" are correct. I feel that memorizing every grammar rule and every exception to every rule is an impossible task so I wouldn't worry too much about why these sentences are correct.I learned my first lessons of the English language about 40 years ago with an English teacher. One of the first grammar rules that he teached his students was the following: the verbs "to be" and "to have" are, as in most languages, irregular verbs and they make their negative and interrogative forms as well as the past tense without the auxiliary verb "to do".
For instance, it is incorrect to say: "I don't have anything to eat" or " Did you have to say that?" as you never say "I don't be a teacher " or "Do I am a teacher" Nevertheless I see these forms of negative and interrogative for the verb "to have" ( did you have, you don't have to..., etc. )everywhere now, including on your web quiz and in other books and writings one would expect to be free of grammar errors.
Can you explain the phenomenon?
The pattern is useful:
Did you have to say that?
Did you have to copy my homework?
Did you have to pick a fight with the biggest guy in the bar?