Advertisement
MeehoweCK

Untitled

Nov 19th, 2020
765
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     int x = 1 + rand() % 100;
  10.     int guessed, counter = 0;
  11.  
  12.     cout << "The number has been drawn. Try to guess!\n";
  13.     do
  14.     {
  15.         cin >> guessed;
  16.         if(guessed > x)
  17.             cout << "Your number is too large :( ";
  18.         if(guessed < x)
  19.             cout << "Your number is too small :( ";
  20.         ++counter;
  21.     } while(guessed != x);
  22.     cout << "Congratulations! You needed " << counter << " attempts to guess the number " << x << endl;
  23.     return 0;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement