I am trying to have my code take the number of authors who worked on a book and then have an array be filled based on however many authors there are. However, whenever I have my getline statement so it can get their whole name, the input is skipped over.
cout << "How many authors are there: ";
cin >> uNumOfAuthor;
cout << endl;
string* uAuthor = new string[uNumOfAuthor];
if (uNumOfAuthor == 0)
cout << "Invalid number of authors.\n";
else if (uNumOfAuthor == 1)
{
cout << "Enter the author's name: ";
cin >> uAuthor[0];
}
else
{
for (int i = 0; i < uNumOfAuthor; i++)
{
cout << "Author " << i << "'s name: ";
getline(cin, uAuthor[i]);
}
}
It works if I only do the first name and just use cin >> uAuthor
.