Question: Write a C++ program using vectors and iterators that allows a user to maintain his or her favorite games. The program should allow the user

Write a C++ program using vectors and iterators that allows a user to maintain his or her favorite games. The program should allow the user to list all game titles, add a game title, and remove a game title. ** Here is what I have so far, I feel like I am almost done. I am just having a problem re-displaying the list after the user enters games to add. When I try to update the display, it lists the ones that were entered the first time, then it skips a line, and then it adds the ones that were entered second. I DON'T WANT IT TO SKIP A LINE!! Why won't it just display all of them consecutively? Then if you have any ideas on how to remove a game from the list that the user specifies! Please and Thank You! My code...

#include // STD IO Stream Library, Keyboard and Terminal Window #include // Allows String Objects Like Character Strings #include // Needed For Vector Objects #include // Needed For Standard Libraries, exit() Function, etc. using namespace std;

int main() { system("Color 0A"); // Lime Green on Black Display

short unsigned int numGames, i; // The Number of Favorite Games of the User & the Indexing Variable Declared as Short Unsigned Integers

//-------------------------Display-------------------------- cout << "\t\t** Welcome to Game Center ** " << endl << endl; cout << "Game Center Will Keep Track of Your Favorite Games. " << endl; cout << "First Think of The Favorite Games That You Like to Play. " << endl; cout << "Next, Count How Many Games That You Have In Mind. " << endl << endl; cout << "Please Enter the Number of Games on Your Favorite(s) List: "; // Prompt User to Enter the Number of Games cin >> numGames; // User Enters the Number of Games They Like to Play cout << endl; cout << "Please Enter Your List of Favorite Games: " << endl << endl;

string game; // User-Entered Game Choice Declared as a Character String vector gameList; // User's Game List Declared as a Vector of Strings

for (i = 0; i <= numGames; i++) { getline(cin, game); // User Enters Each of their Favorite Games, Accounting for Spaces gameList.push_back(game); // Load the gameList Vector with Each Game Entered by the User }

vector::iterator myIterator; // Iterator that Allows You to Edit Elements of a Vector vector::const_iterator iter; // Iterator the Only Allows You to Reference Elements of a Vector, NOT CHANGE THEM!!

cout << " Here Are The Games That You Have Told Me So Far: " << endl; //---------------Display User-Entered Games------------------ for (iter = gameList.begin(); iter != gameList.end(); ++iter) { cout << *iter << endl; // Point To and Display Each Element of gameList Vector }

numGames = 0; // Reset the numGames Variable char response; // User Response Declared as a Character Datatype cout << endl; cout << "Do You Have Any Other Titles You Wish to Add? [y or n]: "; // Ask User If They Want to Add More Games cin >> response; // User Enters Whether They Want to Add More Games cout << endl;

if (response == 'y' || response == 'Y') { cout << "Please Enter the Number of Games You Wish to Add: "; // Prompt User to Enter the Number of Games cin >> numGames; // User Enters the Number of Games They Wish to Add cout << endl; cout << "Please Enter the Games You Wish to Add: " << endl << endl; for (i = 0; i <= numGames; i++) { getline(cin, game); // User Enters Each of their Favorite Games, Accounting for Spaces gameList.push_back(game); // Load the gameList Vector with Each Game Entered by the User } //-----------------Update Display of Games------------------ for (iter = gameList.begin(); iter != gameList.end(); ++iter) { cout << *iter; // Point To and Display Each Element of gameList Vector } }

system("pause");

return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!