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

/* This program acts like a "guessing game". The computer selects a
   random number between 1 and 10, and the user enters numbers until
   they guess the computer's number. When they do, the number of guesses
   made is printed. */

main() {

  int comp_num,    /* Computer's number */
      guess,       /* Number currently guessed by user */
      guesses;     /* Number of guesses made by user so far */

  /* Generate a random number between 1 and 10 */

  comp_num = rand() % 10 + 1;

  /* Initialize the number of guesses to 1 */

  guesses = 1;

  /* Prompt user for first guess */

  cout << "I am thinking of a number between 1 and 10. What is your guess: ";
  cin >> guess;

  /* This loop keeps running as long as the user enters an incorrect guess. */

  while (guess != comp_num) {

    /* Tell user whether the number is too high or low */

    if (guess > number) {
      cout << "Too high! ";
      }
    else {
      cout << "Too low! ";
      }

    /* Prompt for another guess from user */

    cout << "Try again: ";
    cin >> guess;

    /* Increment the count of number of guesses made */
  
    guesses = guesses + 1;

    } /* end of loop */

  /* Once the user enters the correct number, we exit the loop. Now print
     the final number of guesses made. */

  cout << "You guessed it in " << guesses << " guesses!\n";

  }

