Thread: guessing game

  1. #1
    Registered User Inferno's Avatar
    Join Date
    Nov 2003

    guessing game

    hey all, i just have a question about this guessing game code on the site. What exactly is the point of using else to tell the person there wrong and have "you guess to low/high" on there?...There really both just telling you that your wrong

    #include <stdlib.h>
    #include <iostream.h>
    int main()
    int number=rand()%100; 
    int trycount=0;
    while(guess!=number && trycount<8)
    cout<<"Please enter a guess: ";
    cout<<"Too low"<<endl;
    if(guess>number) cout<<"Too high"<<endl;
    cout<<"You guessed the
    cout<<"Sorry, the number was:
    return 0;

  2. #2
    Super Moderator
    Join Date
    Sep 2001
    Make a flow chart of the program. I believe they're telling you "Too low/high" while you you're still in the guessing phase of the game. When you run out of guess is when they'll tell you that you guessed wrong.

  3. #3
    Hardware Engineer
    Join Date
    Sep 2001

    Did you run this program???

    The too-high too-low are intermediate results reported inside the while loop. You only get to the else condition after you fail to guess correctly 8 times, then exit the loop (without guessing correctly).

    The logic is a bit screwy, because you test for the correct guess inside the loop and again after exiting the loop. (It's generally a bad idea to test the same thing twice.)

    Oh... I see sean_mackrory already answered...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 20q game problems
    By Nexus-ZERO in forum C Programming
    Replies: 24
    Last Post: 12-17-2008, 04:48 PM
  2. Need book to program game into multiplayer...
    By edomingox in forum Game Programming
    Replies: 3
    Last Post: 10-02-2008, 09:26 AM
  3. 2D RPG Online Game Project. 30% Complete. To be released and marketed.
    By drallstars in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 10-28-2006, 12:48 AM
  4. Random guessing game
    By Nalif in forum C Programming
    Replies: 16
    Last Post: 10-26-2006, 03:05 AM
  5. Game Independent Anti-cheat Project Needs Programmers
    By GIA Project Lea in forum Projects and Job Recruitment
    Replies: 3
    Last Post: 09-15-2005, 07:41 PM