It does that because scanf is retarded. If possible avoid using it for many reasons. cin also has a similar problem in that when the user enters input and hits enter, the newline remains in the input stream. The next call to cin or scanf or any character input function will result in the newline being read. The problem can be solved by either using
cin.ignore();
or
while ( getchar() != '\n' );

Both of which will clear the input stream by reading and discarding everything up to and including a newline. How do you avoid the problem altogether? Use fgets and cin.getline() to read everything into a string and parse that string into the data you need