Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7763675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:43:07+00:00 2026-06-01T14:43:07+00:00

OK, I have this assignment and I have to prompt the user for data

  • 0

OK, I have this assignment and I have to prompt the user for data about 5 separate basketball players. My question prompts are in a for loop, the loop executes the first time for the first player fine, but when the second players info needs to be entered the first two question prompts are together on the same line, I have fiddled with this and just cannot figure it out, I am sure it is something small that I am apparently missing, thanks for any suggestions on how to fix this.

Here is the output:

Enter the name, number, and points scored for each of the 5 players.
Enter the name of player # 1: Michael Jordan
Enter the number of player # 1: 23
Enter points scored for player # 1: 64
Enter the name of player # 2: Enter the number of player # 2: <------- * questions 1 and 2 *

Here is my code:

#include <iostream>
#include <string>
#include <iomanip>
using namespace std;


//struct of Basketball Player info
struct BasketballPlayerInfo
{
    string name; //player name

    int playerNum, //player number
        pointsScored; //points scored

};

int main()
{
    int index; //loop count
    const int numPlayers = 5; //nuymber of players
    BasketballPlayerInfo players[numPlayers]; //Array of players

    //ask user for Basketball Player Info
    cout << "Enter the name, number, and points scored for each of the 5 players.\n";

    for (index = 0; index < numPlayers; index++)
    {
        //collect player name
        cout << "Enter the name of player # " << (index + 1);
        cout << ": ";
        getline(cin, players[index].name);

        //collect players number
        cout << "Enter the number of player # " << (index + 1);
        cout << ": ";
        cin >> players[index].playerNum;

        //collect points scored
        cout << "Enter points scored for player # " << (index + 1);
        cout << ": ";
        cin >> players[index].pointsScored;
    }

 system("pause");
return 0;

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T14:43:08+00:00Added an answer on June 1, 2026 at 2:43 pm

    After you read a number (e.g., int), there’s still a new-line left in the input buffer that you haven’t read. When you read another number, that skips across any white-space (including new-lines to find a number. When you read a string, however, the new-line in the input buffer is read as an empty string.

    To make it work, you need to get the new-line out of the input buffer before you try to read the string.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have this assignment to simulate allocating data. It goes like this its
So I have this assignment : I need help with question 2. I thought
I have got this assignment question on HMM and I have solved it. I
so I have this assignment and they are asking for data given by Xslt
I'm still not very good with data structures, but I have this homework assignment
I got this question as an assignment: Packages/Naming We have created lot of packages
so we're doing this assignment at Uni and i have a serious craving to
I obviously do not 'grok' C++. On this programming assignment, I have hit a
This is uni assignment and I have already done some stuff. Please go to
Can I optimize the class assignment here at all? I have to do this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.