I would like the user to be able to delete a a player from the vector list based on the jersey number. I just don't know how to do it.
#include <iostream>
#include <vector>
using namespace std;
int main() {
int numPlayers = 5;
vector<int> playerRating(5);
vector<int> playerNumber(5);
bool keepGoing = true;
char userInput = 'a';
int newNumber = 0;
int newRating = 0;
for (int i = 0; i < numPlayers; i++) {
cout << "Enter player " << i + 1 << "'s jersey number: ";
cin >> playerNumber.at(i);
cout << endl;
cout << "Enter player " << i + 1 << "'s rating: ";
cin >> playerRating.at(i);
cout << endl << endl;
}
cout << endl << "ROSTER" << endl;
for (int i = 0; i < numPlayers; i++) {
cout << "Player " << i + 1 << " -- " << "Jersey number: ";
cout << playerNumber.at(i) << ", Rating: " << playerRating.at(i);
cout << endl;
}
cout << endl;
cout << "MENU" << endl;
cout << "a - Add player" << endl;
cout << "d - Remove player" << endl;
cout << "u - Update player rating" << endl;
cout << "r - Output players above a rating" << endl;
cout << "o - Output roster" << endl;
cout << "q - Quit" << endl << endl;
cout << "Choose an option: " << endl << endl;
cin >> userInput;
while (keepGoing == true) {
if (userInput == 'q') {
keepGoing = false;
break;
}
if (userInput == 'o') {
cout << "ROSTER" << endl;
for (int i = 0; i < numPlayers; i++) {
cout << "Player " << i + 1 << " -- " << "Jersey number: ";
cout << playerNumber.at(i) << ", Rating: " << playerRating.at(i);
cout << endl;
}
}
if (userInput == 'a') {
cout << "Enter another player's jersey number: ";
cin >> newNumber;
cout << endl;
playerNumber.push_back(newNumber);
cout << "Enter another player's rating: ";
cin >> newRating;
cout << endl;
playerRating.push_back(newRating);
numPlayers++;
}
if (userInput == 'd'){
cout << "Enter a jersey number: ";
cin >> newNumber;
playerNumber.pop_back();
}
cout << endl;
cout << "MENU" << endl;
cout << "a - Add player" << endl;
cout << "d - Remove player" << endl;
cout << "u - Update player rating" << endl;
cout << "r - Output players above a rating" << endl;
cout << "o - Output roster" << endl;
cout << "q - Quit" << endl << endl;
cout << "Choose an option: " << endl;
cin >> userInput;
}
system("pause");
return 0;
}