You are mixing the >> operator and the getline method with getline using the default newline terminating char, so when you go back to the top of the program by calling main() (bad choice, if even legal, to recursively call main() by the way), the terminating newline char from the call to cin >> is still in the input stream, thereby causing the initial call to getline()--to get name-- to terminate before data entered into name, but the initial call does remove the implicated newline char from the stream so the data that should have been put into name ends up in age. You need to clear the stream of the terminating char by calling ignore() if kyou call getline after calling >> and you use the default terminating newline char for getline(). The exact syntax of ignore() you use is up to you.