Hey all, I'm trying to make a program to have a baseball roster which can be edited and adjusted based on user input. Everything works 100% fine except for one small problem... I can't seem to figure out how to have my program add just one player to the roster on top of everything else without editing the entire roster itself. Any tips on how to fix this? Specifically in my function "addPlayer".
void addPlayer (data player[SIZE]){
for (int i = 0; i < SIZE; i++){
if (player[i].name == ""){
break;
}
else {
cout << "Please enter in the name for player " << i+1 << ": ";
cin >> player[i].name;
cout << "Enter player " << i+1 << "'s number of hits: ";
cin >> player[i].hits;
cout << "Enter player " << i+1 << "'s number of homeruns: ";
cin >> player[i].homeruns;
while (player[i].hits < player[i].homeruns){
cout << "You can't have more hits than homeruns..." << endl << "Please enter a proper amount of homeruns! \(Less than or equal to "
<< player[i].hits << "\): ";
cin >> player[i].homeruns;
}
}
}
}
For clarification on what I'm doing here, I was trying to make it so that if the player at index position [i] was full of another string, it would skip that player and move on to the next index position, repeated until it found empty index position. I know what I did wasn't the right way to do it AT ALL, but I'm looking for some help on what the proper way would be.
void addPlayer (data player[SIZE]){
int i = 0;// so scope is function wide
for ( i = 0; i < SIZE; i++)
if (player[i].name == "") break;
if( i < SIZE ) {
cout << "Please enter in the name for player " << i+1 << ": ";
cin >> player[i].name;
cout << "Enter player " << i+1 << "'s number of hits: ";
cin >> player[i].hits;
cout << "Enter player " << i+1 << "'s number of homeruns: ";
cin >> player[i].homeruns;
while (player[i].hits < player[i].homeruns){
cout << "You can't have more hits than homeruns..." << endl << "Please enter a proper amount of homeruns! \(Less than or equal to "
<< player[i].hits << "\): ";
cin >> player[i].homeruns;
}
else
cout << "All " << SIZE << " spaces are taken already" << endl;
}