Hmmm, I wonder why it somewhat worked with getchar but not with scanf.

Because there is a difference between character and integer input. If you ask for a character, scanf will (try to) give you the character. If you ask for an integer scanf will (try to) give you the integer.

7. It is easier to write an incorrect program than understand a correct one.
40. There are two ways to write error-free programs; only the third one works.*