All pastes #336457 Raw Edit

Unnamed

public text v1 · immutable
·published 2007-02-02 01:19 UTC
rendered paste body

// Define the greatest possible value:
#define MAX_RANGE 100

main ()
{
  int counter=0;
  long value,input;

  srand ( time (NULL) );         // Initialize random generator
  value = rand()%MAX_RANGE+1;    // Get random between 1 and MAX_RANGE

  cout << "\nInsert a value between 1 and " << MAX_RANGE << " : ";

  do {

    cin >> input;                // Get user input
    counter++;                   // increase attempts counter

    if (value>input)             // is value grater than the input?
      cout << "Value is greater than " << input << ". Try again : ";

    else if (value<input)        // if not, is it less?
      cout << "Value is less than " << input << ". Try again : ";

    else {                       // else it is the correct number!
      cout << "That's right! Value was " << input;
      cout << "\nYou have needed " << counter <<" attempts.";
      }

  } while (value!=input);
  return 0;
}