//Charlotte Davies-Kiernan CS1A Chapter 5 P.298 #20
//
/******************************************************************************
*
* Randomize Number Guessing
* ____________________________________________________________________________
* This program will generate a random number for the user to guess, the number
* being between 1 and 100.
* ____________________________________________________________________________
* Input
* guess //Guess the user makes between 1 and 100
* Output
* randomNumber //Random Number the program generates that the user is trying to guess
*****************************************************************************/
#include <iostream>
#include <cstdlib>
#include <iomanip>
using namespace std;
int main()
{
int guess; //INPUT - guess the user makes to try and guess the number
int randomNumber; //OUTPUT - the program will let the user know whether or not they guessed correctly
//
//Random Number Generator
randomNumber = rand () % 100 + 1;
guess = 0;
//
//Prompt User
cout << "Guess the number (between 1 and 100): " << endl;
//
//Check if guess was correct
while (guess != randomNumber){
cin >> guess;
if (guess < 1 || guess > 100){
cout << "Out of range. Please enter a number 1-100." << endl;
break;}
if (guess < randomNumber)
cout << "Too low try again!" << endl;
else if (guess > randomNumber)
cout << "Too high try again!" << endl;
else
cout << "Congratulations!! You've guessed the number!" << endl;
}
return 0;
}