Write a program using vectors and iterators that allows a user to maintain a list of his or her favorite games. The program should allow the user to list all game title, add a game title, and remove a game title.
Being as this is only an exercise and not a real world application, I don't need to be able to write the information to a file (I haven't even gotten far enough in the book to even know how to do that yet).
This is what I have so far:
#include<iostream>#include<vector>#include<algorithm>#include<cstdlib>using namespace std;int main(){ //setup vector<string> games; cout << "1. List Games\n"; cout << "2. Add Games\n"; cout << "3. Remove Games\n"; cout << "4. Quit\n"; int choice; cout << "Choose an option: "; cin >> choice; while(choice == 1 || choice == 2 || choice ==3) { switch(choice) { case 1: for(int i = 0; i < games.size(); i++) cout << games[i] << endl; cout << "Choose an option: "; cin >> choice; break; case 2: cout << "Enter game to add: "; string game; cin >> game; games.push_back(game); cout << "New List:\n"; for(int i = 0; i < games.size(); i++) cout << games[i] << endl; cout << "Choose an option: "; cin >> choice; break; case 3: cout << "List:\n"; for(int i = 0; i < games.size(); i++) cout << (i + ". " + games[i]) << endl; cout << "Enter number of game to remove: "; int remove; cin >> remove; games.erase((games.begin() + remove); cout << "New List:\n"; for(int i = 0; i < games.size(); i++) cout << games[i] << endl; cout << "Choose an option: "; cin >> choice; break; } } //shutdown cout << "Thank you for using chapter 4, exercise 1!"; return 0;}
I include the algorithm header because I want to eventually use the sort function to display the list.
Anyway, here is what bloodshed compiler is saying:
C:\Users\Kenneth Powers\Documents\Projects\C++\Examples\Chapter 4\exercises\1\1.cpp In function `int main()': 42 C:\Users\Kenneth Powers\Documents\Projects\C++\Examples\Chapter 4\exercises\1\1.cpp jump to case label 33 C:\Users\Kenneth Powers\Documents\Projects\C++\Examples\Chapter 4\exercises\1\1.cpp crosses initialization of `std::string game' 49 C:\Users\Kenneth Powers\Documents\Projects\C++\Examples\Chapter 4\exercises\1\1.cpp expected `)' before ';' token 42 C:\Users\Kenneth Powers\Documents\Projects\C++\Examples\Chapter 4\exercises\1\1.cpp [Warning] destructor needed for `game' 42 C:\Users\Kenneth Powers\Documents\Projects\C++\Examples\Chapter 4\exercises\1\1.cpp [Warning] where case label appears here 42 C:\Users\Kenneth Powers\Documents\Projects\C++\Examples\Chapter 4\exercises\1\1.cpp [Warning] (enclose actions of previous case statements requiring destructors in their own scope.)
Any help that can be provided would be greatly appreciated.
And also go easy on me if I made any code that doesn't make sense. I have been using c++ a minimal amount for 2 days and this is the first application I'm making without assistance from the book (besides it being an exercise, there are no instructions past what I have provided).
Edit: It is 0100 where I am right now and I need to get some sleep. Sorry if I don't reply quickly.
Edited by npsken, 20 January 2008 - 01:03 AM.