When data on a stream cannot be converted it stays in the stream buffer. When you type 'bob' scanf() will return 0 and "bob\n" will stay in the stdin's buffer... the latter scanf() will read 1 char leaving "ob\n" in the buffer... In the next iteration, "ob" will cause scanf() to fail and the latter scanf() will leave "b\n"... Third interation: scanf() will fail and the second scanf() will get it, leavind only '\n' on buffer.
Very good answer; I was not able to think of a simple answer based on the OP code; I did not think of the idea of starting from scratch to solve the issue.
And, I would have used an function that the OP might not yet know how to write an user defined function.
Tim S.
"...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson