Advertisement
Guest User

Untitled

a guest
Mar 13th, 2025
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <ctime>
  4. #include <cstdlib>
  5.  
  6. using namespace std;
  7. int player;
  8. bool fact = true, fict = false;
  9.  
  10.  
  11.  
  12. int insert()
  13. {
  14.     cin >> player;
  15.     return player;
  16. }
  17.  
  18. int game(int rnd)
  19. {
  20.     cout << "\nEnter number between 0 and 100:";
  21.     int x = insert();
  22.     if (rnd != x)
  23.     {
  24.         if (rnd < x)
  25.         {
  26.             cout << "Number is lower\n";
  27.         }
  28.         else
  29.         {
  30.             cout << "Number is higher\n";
  31.         }
  32.         return 0;
  33.     }
  34.     else
  35.     {
  36.         cout << "YOU WIN!";
  37.         return 1;
  38.     }
  39. }
  40.  
  41. int main()
  42. {
  43.     int tries = 0;
  44.     srand(static_cast<unsigned int>(time(0)));
  45.     int rnd = rand() % 100 + 1;
  46.     cout << "############\n";
  47.     cout << rnd << endl;
  48.     cout << "############\n\n";
  49.     while (game(rnd) != 1)
  50.     {
  51.         tries++;
  52.         game(rnd);
  53.     }
  54.     if (game(rnd) == 1)
  55.     {
  56.         cout << "It took " << tries << " tries!\n";
  57.         cin >> player;
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement