I have this working like it should (I think) except that it is cutting off the first letter of the first display name unless I add a space before the name. I have tried using just using
cin >> soccer[i].name
but it doesn't work, it skips over the name entering the second time through the loop. Here is my code, any help would be awesome!
#include <cstdlib>
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
struct SoccerPlayer
{
string name;
int num;
int pts;
};
int main(int argc, char *argv[])
{
const int team = 2;
SoccerPlayer soccer[team];
int i;
int total = 0;
int highest = 0;
int pNum;
string pName;
for (i = 0; i < team; i++)
{
cout << "Enter player # " << (i + 1) << "'s full name: ";
cout << endl;
cin.ignore();
cout << endl;
getline(cin, soccer[i].name);
cout << endl;
cout << "Enter player # " << (i + 1) << "'s jersey number: ";
cout << endl;
cin >> soccer[i].num;
if (soccer[i].num < 0)
{
cout << "Invalid entry: Enter a positive number.\n";
cin >> soccer[i].num;
}
cout << endl;
cout << "How many points did player # " << (i + 1) << " score?: ";
cout << endl;
cin >> soccer[i].pts;
if (soccer[i].pts < 0)
{
cout << "Invalid entry: Enter a positive number.\n";
cin >> soccer[i].pts;
}
total += soccer[i].pts;
cout << endl;
}
cout << "Player Name Player Number Points Scored";
cout << endl;
cout << "___________________________________________________________";
cout << endl;
for (i = 0; i < team; i++)
{
cout << left << setw(25) << soccer[i].name;
cout << setw(25) << soccer[i].num;
cout << setw(25) << soccer[i].pts;
cout << endl;
}
cout << endl;
cout << "The total points scored by the team was " << total;
cout << endl;
for (i = 0; i < team; i++)
{
if (soccer[i].pts > highest)
{
highest = soccer[i].pts;
pNum = soccer[i].num;
pName = soccer[i].name;
}
}
cout << endl;
cout << "The player who scored the most points is: " << pName;
cout << endl;
cout << "That player's jersey number is: " << pNum;
cout << endl;
cout << "That player scored " << highest << " points.";
cout << endl;
system("PAUSE");
return EXIT_SUCCESS;
}