/* number guessing game - human does the guessing */ #include #include // needed for the random function #include #include int main() { int x; // holds value of a randomly generated positive integer int guess; // holds value of user guess /* The 3 lines below seeds the random number generator struct timeval tv; gettimeofday(&tv,NULL); // for random see generation srandom((int) tv.tv_usec); // set random seed x = random() % 1000; // generates number between 0-999 cout << "I just thought of a number between 0 and 999 and you have to guess what it is\n"; guess = -1; // this is so that guess != x is assured at start; while (guess != x) { cout << "\nGuess: "; cin >> guess; if (guess < x) cout << "The number is larger\n"; else if (guess > x) cout << "The number is smaller\n"; else cout << "You guessed it!\n"; } // end while loop return 0; }