How to create an array that accepts up to 24 names from User Input

What I currently have is repeating the cout line as many times as there are characters in the user input. For example, if the user inputs "Brad" then it will repeat the cout line 4 times. If the user inputs "Joe Bob" it will repeat the cout like 7 times.

string golferNames[24];
for (int x = 0; x < 24; x++)
{
cout << "Please enter a Golfer's first and last name seperated by a space: " << endl;
cin >> golferNames[x];
}

Any advice would be greatly appreciated.
cin will not work for space split names. you probably want to use getline. if you need to mix getline and cin, you need to read up on how to handle that because they leave the input stream in different conflicting states.

not sure why it would print 4 times for brad. The code you have is correct apart from the above cin and whitespace issue. Do you have more code where there could be a bug?
Last edited on
Topic archived. No new replies allowed.