// Programmer: Scott Emrich // Date: 1/18/08 // Program: // This is a small program that picks a random number between 1 and 100 and asks a user to // guess this number. #include #include using std::cout; using std::cin; using std::endl; int main () { int MagicNumber; int Guess; int Tries = 0; srand(time(0)); // seed the random number generator MagicNumber = (rand() % 100) + 1; cout << "I have a number between 1 and 100" << endl; cout << "Can you guess this number?" << endl << endl; cout << "Please enter your first guess:\n? "; cin >> Guess; // simple loop that will get input until the user guesses correctly do { if (Guess < MagicNumber) cout << "Too low. Please try again.\n? "; else cout << "Too high. Please try again.\n? "; cin >> Guess; Tries++; } while (Guess != MagicNumber); cout << "Awesome! You guessed the number correctly in " << Tries << " tries!\n"; cout << "Goodbye!\n"; }