Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Having an Issue with vectors and pushback

$
0
0
Here is my code. The program runs, but when I enter selection 2 and type in the name of a game to enter into the array, then enter selection 1, nothing appears in the list. I know it's a small error, but after hours and hours of searching, I can't find anything. Can anyone help me out?
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main()
{
    int menuChoice;
    int deleteGame;
    string favoriteGame;
    vector<string> favoriteGames;

    do
    {

        cout << endl << "Welcome to your favorite games list!" << endl;
        cout << "Please choose from the following menu:" << endl;
        cout << "1 - View Current Game list. " << endl;
        cout << "2 - Add Game to list. " << endl;
        cout << "3 - Delete game from list. " << endl;
        cout << "4 - Exit Application. " << endl;
        cin >> menuChoice;

        if (menuChoice == 1)
        {
            cout << "Games Currently in your list: " << endl;
            for (unsigned int i = 0; i < favoriteGames.size(); ++i)
            {
                cout << favoriteGames[i] << endl;
            }
        }
        else if (menuChoice == 2)                                                        
        {
            cout << "Please enter the games name: " << endl;
            getline (cin, favoriteGame);
            cin.ignore( numeric_limits <streamsize> ::max(), '\n' );
            favoriteGames.push_back(favoriteGame);
        }
        else if (menuChoice == 3)
        {
            cout << "Which game would you like to remove from your list (please type the number in which its listed starting with 0): ";
            cin >> deleteGame;
            favoriteGames.erase((favoriteGames.begin() + deleteGame));
        }
        else if (menuChoice == 4)
        {
            cout <<" Thanks for using this application! Goodbye!" << endl;
        }
        }while (menuChoice !=4);
    return 0;
}

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>