When you ask whether you want to repeat, you only read the y, leaving the es queued up in stdin. When you go to read the next number, scanf tries to parse that as a number, fails, and returns without altering num. When you prompt the user, you need to burn that whole line.