Enter Player 1 Name
Chris
Enter Player 1 Number
12
Enter Player 1 Score
30
Enter Player 2 Name
Tommy
Enter Player 2 Number
69
Enter Player 2 Score
30
Name: Chris
Player # : 12
Score : 30
Name: Tommy
Player # : 69
Score : 30
Team Final Score: 60
--------------------------------
Process exited with return value 0
Press any key to continue . . .
SO when i try getline(cin,team1[a].pname); it does not work, just skips the input for player 2
# include <iostream>
# include <string>
using namespace std;
struct team
{
string pname;
int pnumber;
double pscore;
};
int main()
{
const int item=2;
team team1[item];
long int total=0;
for(int a=0; a<item; a++){
cout<<"Enter Player "<<a+1<<" Name\n";
getline(cin,team1[a].pname);
cout<<"Enter Player "<<a+1<<" Number\n";
cin>>team1[a].pnumber;
cout<<"Enter Player "<<a+1<<" Score\n";
cin>>team1[a].pscore;
total+=team1[a].pscore;
Enter Player 1 Name
Christopher Desir
Enter Player 1 Number
15
Enter Player 1 Score
30
Enter Player 2 Name
Enter Player 2 Number
15
Enter Player 2 Score
30
Name: Christopher Desir
Player # : 15
Score : 30
Name:
Player # : 15
Score : 30
Team Final Score: 60
--------------------------------
Process exited with return value 0
Press any key to continue . . .
You could see how it skips the input of player 2 name;
cin leaves a newline character('\n') in the stream, so when you call getline for the second player, no characters will be extracted as there is a '\n'.