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
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
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
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started