CSCI 3326

Assignment #2

Due date:  Start of class Wednesday, 1/21/2008

 

Hand in:

1)  Turn in your source code to me as an email attachment.  The subject of the email must be:

cs3326hwk2

2)  Also turn in a hardcopy of your source code along with a printout of a sample run.

 

 

                                                            

HiLo Guessing Game

 

This assignment utilizes:

- random numbers

- loops

- conditional statements

- basic input/output

 

 

Write a program to play the Hi-Lo guessing game discussed in class.  In particular, your program should:

 

·         Generate a random number from 1 to 100.

·         Ask the user to guess the number

·         If the user is right, the game ends

·         If the user's guess is too high or too low, the program informs the user of that fact and asks for another guess.

·         This repeats until the user gets the number correct.

 

Further, your program should keep track of how many guesses the user takes to get the number right.  An appropriate insult/compliment should then be issued to the user.  For example:

        11 or more "What a terrible score!..."

        9-10       "Not too shabby, but not too good either...

        7-8        "That's pretty good but you can do better..."

        5-6        "That's a very good score..."

        0-4        "Amazing! Or was it luck?"

 

Here is a sample run:

 

    Lets play a Number Guessing Game!

    Guess a number between 1 and 100

    40

    Too low!!

    Guess a number between 1 and 100

    90

    Too high!!

    Guess a number between 1 and 100

    60

    Too high!!

    Guess a number between 1 and 100

    50

    Too low!!

    Guess a number between 1 and 100

    55

    Too low!!

    Guess a number between 1 and 100

    56

    You win!!

    It took you 6 guesses.

    That's a very good score...

 

 

Extra Credit 1 (10 extra points)

(This is easy, you might as well do it!)

 

Make the following improvements to your program:

 

·         Instead of always guessing from 1-100, ask the user to input the range of numbers to guess between.

·         Before playing, request some personal information about the user.  Then, during the game, have the program spew random comments at the user based on this information.

·         Make your program do something cool other than what is already listed.

 

 

Extra Credit 2 (50 extra points)

·         Write a second version of the Hi-Lo game, except that instead of the user guessing the number, the computer tries to guess a number the user is thinking of. That is, the computer makes a guess, and the user tells the program if the guess is too high or too low.

·         To get points for this version, your program should always guess the number within, say, 10 guesses.