Assignment: #GuessingGame Due: 04/22/2017 Points: 7

Specification

Write a program that allows the user to play number guessing games.

Playing a Guessing Game

Use rand() function from the Standard C Library to generate a random number between 1 and 100 (inclusive). Prompt the user to enter a guess. Loop until the user guesses the random number or enters a sentinel value to give up. Print an error message if the user enters a number that is not between 1 and 100. Print an error message if the user enters a wrong guess more than once. Duplicate wrong guesses count as only one wrong guess. After five wrong guesses, the user is given help (higher or lower messages). After a game has been completed prompt the user to see if they want to play again. The user is allowed to play at most 256 games.

Post Game Playing Processing

Print the following prior to exiting the program.

Required Manifest (Named) Constants

Your program must define the following manifest constants prior to the main() method and they should be used through out your code.

   const int MIN_NUMBER = 1;
   const int MAX_NUMBER = 100;
   const int EXIT_VALUE = -1;
   const int MAX_GAMES = 256;
Help Generating Random Numbers

At the top of the file.

   #include <iostream>
   #include <stdlib.h>
   #include <time.h>

At the top of the main() function call the srand() function to seed the random number generator.

   int main(int, char**) {
      srand(time(NULL));   // seeds the random number generator
      ...
   }

To get a random number that's between 1 and 100.

   int random_number = rand() % MAX_NUMBER + 1;
      // rand() returns a number between 0 and some large number
      // % operator used to get the number beween 0 and MAX_NUMBER
Example Game

Assume the computer generated random number is 34 for game #1, 73 for game #2, and 99 for game #3. For example purposes, user inputs are enclosed in brackets <>.

*** You are playing the CSC100 Guessing Game ***

Enter a number between 1 and 100 (-1 to give up): <3>
nope...
Enter a number between 1 and 100 (-1 to give up): <1001>
1001 is too big...
Enter a number between 1 and 100 (-1 to give up): <0>
0 is too small...
Enter a number between 1 and 100 (-1 to give up): <33>
nope...
Enter a number between 1 and 100 (-1 to give up): <50>
nope...
Enter a number between 1 and 100 (-1 to give up): <21>
nope...
Enter a number between 1 and 100 (-1 to give up): <21>
what part of nope don't you understand?
Enter a number between 1 and 100 (-1 to give up): <41>
nope...
Enter a number between 1 and 100 (-1 to give up): <27>
nope...higher
Enter a number between 1 and 100 (-1 to give up): <57>
nope...lower
Enter a number between 1 and 100 (-1 to give up): <34>
*** GOT IT *** it took you 8 guesses

Do you want to play again? (y/n): <y>

Enter a number between 1 and 100 (-1 to give up): <99>
nope...
Enter a number between 1 and 100 (-1 to give up): <-1>
*** QUITTER ***

Do you want to play again? (y/n): <y>

Enter a number between 1 and 100 (-1 to give up): <21>
nope...
Enter a number between 1 and 100 (-1 to give up): <99>
*** GOT IT *** it took you 2 guesses

Do you want to play again? (y/n): <n>

Thanks for playing the CSC100 guessing game.

You played 3 games and won 2 of them.
Your winning percentage is 66.7%.