   A game I made a month ago...Critic it for me.
  Hello everyone,A month ago I made this game to refresh my C++ knowledge.  It is a Guess the Number game.  I actually made a twist to it by also including a game where the user picks the number and the computer guess it.  The computer AI for that game is very simple, so it does suck.  Please tell me the things I should fix for future programming, and things to work on.  //Guess the Number game//By: Carl J. Loucius#include <iostream>#include <cstdlib>#include <ctime>//make a namespace for commonly used things from the std namespacenamespace stdVariables{using std::cout;using std::cin;}//declare functions for this gamevoid IntroScreen();void PlayerGuessGame();void ComputerGuessGame();void ClosingScreen();char Menu();int main(){using namespace stdVariables;char choice; IntroScreen();system("PAUSE");system("cls");//main part of the gamedo {system("cls");choice = Menu();if (choice == '1'){system("cls");PlayerGuessGame();system("PAUSE");system("cls");}else if (choice == '2'){system("cls");ComputerGuessGame();system("PAUSE");system("cls");}else if (choice == '3'){system("cls");ClosingScreen();system("PAUSE");}else {cout << "\nYou did not enter a correct choice.  Try Again!\n\n";system("PAUSE");system("cls");}}while (choice != '3');return 0;}//a function for the player guess the number gamevoid PlayerGuessGame(){using namespace stdVariables;srand(time(0)); //seed random number generatorint theNumber = (rand() % 100) + 1;int tries = 0;int guess;cout <<"\t Guess the Number Game\n\n";do {cout <<"Enter a guess: ";cin >> guess;++tries;if (guess > theNumber)cout << "Too high\n\n";if (guess < theNumber)cout << "Too low!\n\n";}while (guess != theNumber);cout << "That is it! You got it in " <<tries <<" guesses!\n\n";}//a function for the computer guess the number gamevoid ComputerGuessGame(){using namespace stdVariables;int guess;int tries = 0;int theNumber;cout <<"Enter a number that the computer will try to guess. \n";cin >> theNumber;do{guess = (rand() % 100) + 1;++tries;}while (guess != theNumber);cout<<"The computer found out the number was " <<theNumber <<" after " <<tries <<" tries.\n\n";}//the menu of the program; will return a choice back to the main functionchar Menu(){using namespace stdVariables;char theChoice;cout <<"==============================Menu====================================\n";cout <<"=================== 1- You guess the random number ===================\n";cout <<"=================== 2- Computer guess the number   ===================\n";cout <<"=================== 3- Exit    ===================\n";cout <<"======================================================================\n\n";cout <<"Please enter a number choice.\n";cin >> theChoice;return theChoice;}//displays an intro screen for the programvoid IntroScreen(){using namespace stdVariables;cout<<"====================================================\n";cout<<"===============Guess the Number Game================\n";cout<<"====================================================\n\n";cout<<"Created By: Carl J. Loucius\n\n";}//displays a closing screen for the programvoid ClosingScreen(){using namespace stdVariables;cout<<"====================================================\n";cout<<"===============Guess the Number Game================\n";cout<<"====================================================\n\n";cout<<"Thank you for playing the Tic-Tac-Toe Game.  Please play again. \n\n";}Also, can someone please tell me the uses of std::endl and \n.  What the main difference between them and when I should use either of them.  I had always used std::endl before this program, but changed to \n.   
  Why the superfluous namespace?Quote:Original post by acddklr07Also, can someone please tell me the uses of std::endl and \n.  What the main difference between them and when I should use either of them.  I had always used std::endl before this program, but changed to \n.std::cout << std::endl prints a newline and then flushes the output, while std::cout << "\n" just prints a newline.   ;  Use the using namaspace..as Global is better I think..   ;  Good job!  Keep up the good work, and we look forward to seeing more games from you!   ;  nice job!you can try to improve your AI by making a random mixture of:1. pick a random number inside the left range2. pick the middle number of the left range(with left range i mean for example if you pick 33: 34-100 if the number-to-be-guessed is higher, 0-32 if it's lower. for example if it's higher and you then pick 90, if it's higher the range is now 91-100, otherwise it's 34-90)picking the middle number of the range should be the fastest non-random way of guessing it as far as I know.good luck and keep up the good work of course!   ;Quote:Original post by saltdgUse the using namaspace..as Global is better I think..Not really - in general try to avoid using namespace std; (this advice mainly applies to header files however).@acddklr07:As Roboguy hinted, we don't normally wrap namespaces (especially the std one) in this way, there's notthing wrong with just doing: std::cout "My Text";Now for a few pedantics... [wink]Try to avoid making calls to System, the reason is that they are non-portable, if you want to pause the program to wait for the user then prefere std::cin.get().  There is actually no portable way to clear a screen in C++ because there's no guarantee there is a screen, so, with portability in mind, I'd recommend you write a wrapper for it:void clearScreen() {    system("cls");}This way if you ever move (your code) to Linux for example all you have to do is change a tiddly bit of code in this little function and all is well [smile].I notice you like to use do { ... } while(blah);, whilst your particular use of this is kind of justified for in general programming practice I'd rather see while(blah) { ... } so that when reading from top to bottom I know what the fail-case is before I read the loops body.Other than that, I can quite easily say I've seen far-far worse attempts at programming!Keep up the good work, very well done!   ;  I want to thank everyone for replying to this.  I want to thank you dmatter for the suggestions.  I would take what you said to help me with further programs.  Also, I am going to change the do { }while(blah) to while loops.  I did that, because I know that the do loop always go through it atleast once, but did not think if a while loop can be used.  I would like to thank ForestMaster for the suggestion on how to improve the computer AI.  I am going to try to figure it out and implent it.  Well I would be posting more things soon to be critic, so hopefully you guys would be able to critic them when I do. :)!~Carl J. Loucius   