123456789101112131415161718192021
#include <iostream> #include <cstdlib> using namespace std; int main () { int number = rand()%100; int guess = -1; int trycount = 0; while (guess != number && trycount < 8) { cout << "Please enter a guess: "; cin >> guess; if (guess < number) cout << "Too low" << endl; if (guess > number) cout << "Too high" << endl; } if (guess == number) cout << "You guessed the number" << endl; else cout << "Sorry, you are wrong." << endl; return 0; }