What you need to do is to compile at a high warning level, and pay attention to warnings. Actually, even at a low warning level your compiler is probably warning you about a typo error in your third scanf call, but you're probably ignoring the warning. There are other warnings that you should pay attention to as well.