   A new program I made....please critic it for me.
  Hello,Well I am refreshing my skills in C++ and I am using a book called Beginning C++ Game Programming.  Well I am in Chapter 5, and it introduced a new topic that I never learned and therefore I made a program to practice it.  The chapter was on Standard Template Library.  Well here is the source code://Game Catalog Program//Program Use:  To store games own, list it, add them, and delete them#include <iostream>#include <vector>#include <string>using namespace std;//declare functions void ListGames();void AddNewGame();void DeleteGame();void IntroScreen();void ClosingScreen();char Menu();//declare global variables for the programconst double VERSION_NUMBER = 0.1;vector<string> listOfGames;//main function for the programint main(){char choice;IntroScreen();cin.get();system("cls");//a do while loop that continue to loop until user inputs 4, which correspond to quit.do{choice = Menu();if(choice == '1'){system("cls");AddNewGame();cin.get();system("cls");}else if(choice == '2'){system("cls");DeleteGame();cin.get();system("cls");}else if(choice == '3'){system("cls");ListGames();cin.ignore();cin.get();system("cls");}else if(choice == '4'){system("cls");ClosingScreen();cin.ignore();cin.get();}else {cout<<"You did not enter a correct choice try again."<<endl;cin.ignore();cin.get();system("cls");}}while (choice != '4');return 0;}//a function for the intro screenvoid IntroScreen(){cout<<"=========================================================="<<endl;cout<<"================== Game Catalog v" << VERSION_NUMBER <<" ====================="<<endl;cout<<"=========================================================="<<endl<<endl;cout<<"Created by: Carl J. Loucius"<<endl<<endl;cout<<"Use of Program:  Game Catalog stores the name of the game you own, be"<<endl;cout<<"able to add new games that you get to the list, delete games from the "<<endl;cout<<"list, and be able to list the games."<<endl;}// a function for the closing screenvoid ClosingScreen(){cout<<"=========================================================="<<endl;cout<<"================== Game Catalog v" << VERSION_NUMBER <<" ====================="<<endl;cout<<"=========================================================="<<endl<<endl;cout<<"Thank you for using this program.  Please come again to use it."<<endl;}//a function that asks the user for a name game to enter and store it in a vector, and it pushes //back the last elementvoid AddNewGame(){const int NUMOFCHAR = 100;char nameOfGame[NUMOFCHAR];cout<<"Please enter the name of the game you want to add to the list."<<endl;cin >> ws;cin.getline(nameOfGame, NUMOFCHAR);listOfGames.insert(listOfGames.begin(), nameOfGame);}// a function that will iteriate through the list of gamesvoid ListGames(){vector<string>::const_iterator iter;cout<<"Here's the list of your games: "<<endl<<endl;int i = 0;for ( iter = listOfGames.begin(); iter != listOfGames.end(); ++iter){cout << i << " - " << *iter <<endl;++i;}}//this function shows the list and asks the user to input a number for the game they want to delete,//and it deletes the gamevoid DeleteGame(){ListGames();int num;cout <<"Please type in the number that you want to delete from the list."<<endl;cin >> num;listOfGames.erase((listOfGames.begin() + num));}//this function is for the menu and it returns the user choice.char Menu(){char theChoice;cout<<"=========================================================="<<endl;cout<<"================== Game Catalog v" << VERSION_NUMBER <<" ====================="<<endl;cout<<"=========================================================="<<endl;cout<<"1 - Enter New Game"<<endl;cout<<"2 - Erase A Game From The List"<<endl;cout<<"3 - Show Game Collection"<<endl;cout<<"4 - Quit"<<endl<<endl;cout<<"Enter the corrensponding number choice"<<endl;cin >> theChoice;return theChoice;}Please critic it.  I would love to hear about things that will improve it, and what I should avoid to do.  Also, do anyone know a place that tells you all the things in the std namespace? Also, I will be improving this program throughout the book, and doing other side projects.~CJ   
  Don't get into the habit of doing:using namespace std;For a bit of practice you could use the stl For_Each class for the List Items function, instead of the loop. Getting in some practics with std::sort and the predicate stuff would be good too.   ;  Just a couple of things that I see...As quoted above, try to avoid using namespace std. This includes all declarations of the STD namespace in your source files, increasing compilation times. That is...// Instead of...#include <iostream>using namespace std;cout << "Hello, world!";// do this...#include <iostream>std::cout << "Hello, world!";Alot of your variables are never initialized. You should get in the habit of initializing all variables.I don't like the use of system(), but that is just my personal taste.Besides the global variables, everything else looks nice![smile];  *Dont use global variables!I was doing the same , and then i learned to use reference variables(some members here helped me too ...:)).example:using std::string;using std::cout;using std::cin;using std::endl;void addname(const string& name, vector<string>& list){listOfGames.insert(list.begin(), name);}string getinput(string text){cout<<text<<endl;string ws;cin >> ws;return ws;}int main(){vector <string> OUR_vECTOR;addname(getinput("Please enter the name of the game you want to add to the list."),OUR_VECTOR);}*Avoid using if statements if possible, and replace them with "switch()".example:switch(state){case '1':......your code..break;case '2'...etc}Good luck!.   ;  Alrighty! I didn't know that I should avoid using global variables until now, so thanks for letting me know :)!  I was hoping someone tell me a website or anything that tells you what is in the std namespace that is used.  I know in the book it said something about some things that are in the std namespace for the vectors, or something like that and he used using namespace std when going over that stuff.  I know that using namespace std is a bad choice because it gives you all these extra variables, so do anyone know a website or a book that tells you everything about the namespace std?  Also, thanks about the comment about use switch statements.  I am going to do try to do that more often.  Also, thanks for telling me about references, cause actually that is the next thing it goes into in the book, which I never learned when I took the class(it was a highschool class).Also, Crypter can you please tell me why I should initialize them, it would really benefit me.  Thanks everyone for all the comments I appericiate them.~Carl J. Loucius   ;  I find the SGI website is a good resource - clickyThe reason you should initialise variables is simply because it's safer, accessing an uninitialised variable is dodgy.   ;Quote:Original post by 3Dgonewild*Avoid using if statements if possible, and replace them with "switch()".example:Why is that? What is wrong with if statements? Sure they may take longer to write, but is there any inherent performance issue with it? I tend to prefer if statements unless I'm planning on comparing a value to more than 5 other values.Also, in regards to the 'using namespace std' part, you could use std::cout every time you wanted to write out text, or you could simply put 'using std::cout;' at the top and then continue just writing cout.   ;Quote:Also, Crypter can you please tell me why I should initialize them, it would really benefit me. Thanks everyone for all the comments I appericiate them.C++ does not initialize anything for you. Because of this, the memory block that your variable resigns in contains whatever was placed there prior to its use. This is, in other words, garbage.For an example:#include <iostream>int main () {   int i;   std::cout << i;   return 0;}This program will print a completely random number when executed, because the memory location where "i" is located contains some random data.This is much more worse with pointers, as uninitialized pointers essentially point to some random memory location, which can result to alot of big problems (Memory corruption, stack corruption, executing random code/instructions, or, in most cases, an access violation exception)It is much safer to insure a varable contains some "dummy" value, rather then assuming it.Quote:*Avoid using if statements if possible, and replace them with "switch()".There is nothing bad about using simple if statements. A switch, in effect, is a series of tests, similar to an if statement--because of this, one does not gain any benefits.If you do have a large series of if statements, however, then switch{} is much more feasible, and recommended. For a very small list, if statements suffice.;  You should always validate the input from user.    int num;    cout <<"Please type in the number that you want to delete from the list."<<endl;    cin >> num;    if(num >= listOfGames.size())    {   std::cout << "No such game.." << std::endl;   return;    }   listOfGames.erase((listOfGames.begin() + num));