//Sam Partovi CS1A Chapter 5, P 298, #20
//
/*******************************************************************************
*
* SIMULATE NUMBER GUESSING GAME
* ____________________________________________________________
* This program simulates a number guessing game with a randomly generated
* integer with a specified maximum and minimum value.
* ____________________________________________________________
*INPUT
* guess : Guessed number to be validated as correct or incorrect
*
*OUTPUT
* randomNumber : A randomly generated number seeded by system time.
******************************************************************************/
#include <iostream>
#include <iomanip>
#include <ctime>
using namespace std;
int main ()
{
int guess; //INPUT - Number to be validated against randomNumber
int randomNumber; //INPUT - A randomly generated number seeded by system time.
//GENERATE A RANDOM NUMBER
srand((int)time(NULL));
randomNumber = rand() % 11;
//PROMPT FOR USER GUESS
cout << "Guess the random number between 0 and 10: ";
cin >> guess;
//VALIDATE GUESS RELATION TO RANDOM NUMBER
while (true) {
if (guess > randomNumber) {
cout << "\nToo high, try again! ";
}
else if (guess == randomNumber) {
cout << "\nCorrect! The number was " << randomNumber << ".\n";
break;
}
else {
cout << "\nToo low, try again! ";
}
cin >> guess;
}
return 0;
}