After you read choice
in the displayMenu
subroutine, you leave the remainder of the user's input line. Specifically, you leave the end-of-line indicator: '\n'
. Later, when you read newperson->name
, you are actually retrieving the remainder of the menu line, and not the name line.
You can use istream::ignore
to consume the rest of menu choice line, before trying to read the name.
Replace the last two lines of displayMenu
with these:
cin >> choice;
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
return choice;