Skip to content

Instantly share code, notes, and snippets.

@amankharwal
Created December 4, 2020 08:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amankharwal/fffd0bfebc5c934276b3f6a2bf629afd to your computer and use it in GitHub Desktop.
Save amankharwal/fffd0bfebc5c934276b3f6a2bf629afd to your computer and use it in GitHub Desktop.
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
int num, guess, tries = 0;
srand(time(0)); //seed random number generator
num = rand() % 100 + 1; // random number between 1 and 100
cout << "Guess My Number Game\n\n";
do
{
cout << "Enter a guess between 1 and 100 : ";
cin >> guess;
tries++;
if (guess > num)
cout << "Too high!\n\n";
else if (guess < num)
cout << "Too low!\n\n";
else
cout << "\nCorrect! You got it in " << tries << " guesses!\n";
} while (guess != num);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment