C++

profileh2o
2.docx

Number Guessing Game (.cpp file)

The purpose of this exercise is to introduce you to some of the basics of C++ programming.

 

In this exercise, you will implement a simple number guessing game. The computer will randomly select a number between one and ten, your player will enter a guess, your program will compare the two numbers, and if the player guessed correctly she or he wins.

 

Requirements:

1. [10 points] your program source code includes your name and the project name and number

2. [10 points] your program source code is neatly and consistently formatted (type gg=G in vim to format your code)

3. [15 points] your program compiles and runs without errors

4. [10 points] computer generates a random number  between one and ten (the range can be larger).

5. [10 points] prompt for and read in the player’s guess

6. [10 points] compare the player’s guess to the computer’s number

7. [10 points] display an appropriate message to the player to let them know whether they won or lost

 

For extra credit

1. Have the computer tell the user "higher" or "lower" if the player’s guess is higher or lower than the computer’s number

2. Allow the player select from three difficulty levels:

a. Easy 1-10, three guesses

b. Medium 1-50 four guesses

c. Hard 1-100, five guesses

Random number generator

include the following libraries:

#include <cstdlib>
#include <ctime> 


in main include the following:
 
int randomNumber;  // this variable will hold the random number

/* initialize random seed: */  
srand ( time(NULL) );  

/* generate secret number: between 1 and 10 */ 
randomNumber = rand() % 10 + 1;