Guess My Number Game (Lab Report 5)

This lab is designed to give you practice with loops and conditionals, while exploring ideas about random numbers.

While games may seem to be frivolous, digital games have pushed the improvement of computer hardware and operating systems since Christopher Strachy decided to program a computer to play checkers (aka "draughts") in 1951. Also, most of the skills you will practice in this lab will have long-term utility in more serious projects during your career.

Review the reading on random numbers for how to utilize random numbers in C.

Overview

Your program will pick a random number between 1 and 100 (inclusive) that will be the target number that the player needs to guess.

The player will have up to 10 turns in which to guess the correct number.

For each turn, ask the user to guess the number. If the player's guess is less than the target number, print a message that the guess was too low. If the player's guess is greater than the target number, print a message that the guess was too high. If the player's guess is equal to the target number, congratulate them for guessing the right number and tell them how many guesses they had made.

If the player runs out of turns without guessing the right number, print a message that tells them that they used up all of their turns and what the target/correct number was.

Details

Process

You will need to use a loop to ask the player to make guesses until the correct number is guessed or until the number of turns is exhausted. You possibly could use a for loop for this, but the while loop (with a complex conditional) is a more natural choice.

Input

During each loop, your program will need to read in an integer from the user.

Output

Your program needs to first give the player an introductory message about the nature of the game. You should be able to ask a friend or family member to play the game and NOT give them any verbal instructions.

With each turn, you need to prompt the user for another guess and let them know if that guess is too high, too low, or correct.

At the end, tell the user if they guessed correctly or not. If they did not guess correctly, you need to tell them what the right number was. If they guess correctly, you need to tell them how many turns it took to get the right number.

Testing

You must submit a test plan which includes the numbers or the strategies you intend to try to determine if your program is working correctly. Please submit your test plan as a PDF (not a word document or any other type of text document).

During testing, I suggest that you print out the random number that is the target so that you know what to expect for each guess you make. You can comment out that printf statement if you give the program to someone else to play.

Be sure to test the scenario in which you do not guess correctly within 10 turns. You may need to make poor guesses deliberately inorder to achieve this condition. You must also test guesses at the endpoints of the acceptable range as well as invalid numbers. You do not need to recover from non-numeric guesses.

Test at least six plays of the game. Try numbers above and below the target number to be sure that the conditional statements are working correctly. And test at least one in which you guess the correct number after a couple of incorrect guesses.

Grading

Make sure you follow the guidelines on the Submitting Work page as well as the course style guide. In particular, you must include an Academic Honesty Statement! Your Academic Honesty Statement must include the names of all people and sources you consulted while completing this lab.

You must submit a test plan (a PDF please) and a test script. These must be separate from the source (.c ) file. These are the instructions for creating a test transcript.

Do not include a Makefile or compiled files. Submit your project in Gradescope.

You may not use any global variables! Use of a global variable will mean a reduction of 5 points. Also, your program must compile on MathLAN and run without compile errors or crashing.

This project will be worth 18 points based on the following criteria:

Acknowledgements

This exercise was inspired by a project in Jay McGavren's Head First Ruby: A Brain-Friendly Guide. But it is readily adaptable to many imperative programming languages such as C.