Code:
//A Program that allows a user to maintain a list of his favorite video games.
//Using Vectors and Iterators
#include <vector>
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
string game;
string choice;
vector<string>::iterator myIterator;
vector<string>::const_iterator iter;
cout << "\t\t\tWelcome to Game Manager 3.0\n\n\n";
vector<string> games;
cout<< "Add a Video Game to your list: ";
cin >> game;
games.insert(games.begin(), game);
cout<< "Press 1 to add another game\nPress 2 to list your current games\nPress 3 to remove the last game\nEnter 'quit' to exit\n\n ";
cin >> choice;
while (choice != "quit")
if (choice == "1")
cout << "Add a game: ";
cin >> game;
games.insert(games.begin(), game);
cout<< "Press 1 to add another game\nPress 2 to list your current games\nPress 3 to remove the last game\nEnter 'quit' to exit\n\n ";
cin >> choice;
if(choice == "2")
for ( iter = games.begin(); iter != games.end(); ++iter)
{
cout << *iter << endl;
}
cout<< "Press 1 to add another game\nPress 2 to list your current games\nPress 3 to remove the last game\nEnter 'quit' to exit\n\n ";
cin >> choice;
if (choice == "3")
cout<< "Select the game you want to remove: ";
cin>> game;
if (false)
cout<<"That game is not in the list";
else
games.erase(find(games.begin(), games.end(), game));
cout<<"Your list is now: \n";
for ( iter = games.begin(); iter != games.end(); ++iter)
{
cout << *iter << endl;
}
cout<< "Press 1 to add another game\nPress 2 to list your current games\nPress 3 to remove the last game\nEnter 'quit' to exit\n\n ";
cin >> choice;
return 0;
}

New Topic/Question
Reply




MultiQuote



|