Skip to content

Instantly share code, notes, and snippets.

@kdmkdmkdm
Created January 26, 2013 08:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kdmkdmkdm/4641069 to your computer and use it in GitHub Desktop.
Save kdmkdmkdm/4641069 to your computer and use it in GitHub Desktop.
needstweaking
// favoritegamesprogram.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
// Favorite Games Program
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
vector<string>::const_iterator iter;
// Pre-set favorite games:
vector<string> faves;
faves.push_back("Mario");
faves.push_back("Zelda");
faves.push_back("Warcraft");
bool quit = false;
while(!quit)
{
// Ask the user if they want to add a game, remove a game, dislay the list, or quit
int choice;
cout << "1 - Add\n2 - Remove\n3 - Display list\n4 - Quit\nWould you like to add a game, remove a game, display list, or quit: ";
cin >> choice;
switch(choice)
{
case 1:
{
string titleAdd;
cout << "Please enter your game's title: ";
cin >> titleAdd;
faves.push_back(titleAdd);
break;
}
case 2:
{
string titleRemove;
cout << "Please enter the game's title that you'd like removed: ";
cin >> titleRemove;
iter = find(faves.begin(), faves.end(), titleRemove);
if (iter != faves.end())
{
faves.erase(iter);
cout << "Your requested game has been erased." << endl;
}
else
{
cout << "Your game title was not found in the list.";
}
break;
}
case 3:
{
cout << "\nYour favorite games:\n";
for (unsigned int i = 0; i < faves.size(); ++i)
{
cout << faves[i] << endl;
}
cout << endl;
break;
}
case 4:
{
int quitChoice;
cout << "1 - Yes\n2 - No\nAre you sure you want to quit: ";
cin >> quitChoice;
switch(quitChoice)
{
case 1:
{
quit = true;
cout << "Quitting..." << endl;
break;
}
case 2:
{
quit = false;
break;
}
default:
{
cout << "You made an illegal choice.";
break;
}
break;
}
}
default:
{
cout << "You made an illegal choice." << endl;
break;
}
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment