Site hosted by Angelfire.com: Build your free website today!

 

Program #16 

 

 

 


You’ve probably played the “number guess” game at some point in your life.  Someone thinks of a number between 1 and 100 and you are asked to guess the number.  You will be told “higher” or “lower” as you guess.  If you guess it correctly in a certain number of guesses, you win.  If it takes too many guesses, the other person wins.

 

The computer will “think” of a number (1-100).  Use random (100)+1;

(you will also need stdlib header file and randomize( ); statement just after declaration of variables.

 

If it takes more than 7 guesses, you lose.

 

The computer is thinking of a number between 1 and 100.

            Make your guess… 50

Too high! Guess lower… 25

Too low! Guess higher… 37

Too high! Guess lower… 31

Too high! Guess lower… 28

Too low! Guess higher… 29

CORRECT!!!!!!!!!!!!!! You guessed in 6 tries.

 
Like this…

 

?
 

 

 

 

 

 

 

 

 


            (OR sorry, the game is over.  That was your seventh guess. The number was 32.)

 

Hint: have a random statement as your program starts.  Then start do…while loop that checks as the end if guess! =num or count <= 7

            Cout<<”please make your guess”<<endl;

            cin>>guess;

                        do {

                        count=count+1 // don’t forget to start count at 0

                        if ( _____ ) cout<<     <message>       <<endl;

                        }while( ________ )

           

 

It is good to have an end to journey toward; but it is the journey that matters, in the end.

Ursula K. Le Guin