I am trying to write a program for a game list. I have it all done but I can't get it to prevent users from entering duplicate information. here is my code:
int main ()
{
cout << "\t\t\tTHE GAME LIST\n\n";
cout << "\vWelcome to your game list!\n";
vector< string >gameInventory;
string ask;
bool correctMenu = false;
do {
cout << "\nDo you want to: find, list, add, remove, remove all, quit?\n " << endl;
cin >> ask;
if (ask == "find") {
string gameToFind;
cout << "\vInput game to find: " << endl;
cin >> gameToFind;
for (vector< string >::const_iterator iter = gameInventory.begin(); iter != gameInventory.end(); ++iter) {
if (*iter == gameToFind) {
cout << "\vThe game "<< gameToFind << " has been found!\n";
}
else {
cout << gameToFind << " is not in your inventory\n";
}
}
}
if (ask == "list") {
int itemNum = 0;
for (vector< string >::const_iterator iter = gameInventory.begin(); iter != gameInventory.end(); ++iter) {
cout << ++itemNum << ")" << *iter << endl;
}
}
if (ask == "add") {
string addGame;
cout << "What do you want to add?\n" << endl;
cin >> addGame;
vector< string >::const_iterator iter = gameInventory.begin();
bool found = false;
do {
if (*iter == addGame) {
cout << "yo";
found = true;
}
else {
gameInventory.push_back(addGame);
sort(gameInventory.begin(), gameInventory.end());
cout << "You've added " << addGame << " to your game list.\v"<< endl;
cout << "You now have " << gameInventory.size() << " in your game list.\n";
}
++iter;
} while (iter != gameInventory.end() && !found);
}
if (ask == "remove") {
string itemToRemove;
cout << "\vWhich game do you want to remove?" << endl;
cin >> itemToRemove;
bool found = false;
for (vector< string > ::iterator iter = gameInventory.begin();
iter != gameInventory.end() && !found; ++iter){
if (*iter == itemToRemove && !found) {
gameInventory.erase (iter);
found = true;
}
}
}