SHARE
TWEET

Untitled

Tapka Aug 2nd, 2019 115 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <cstdlib> // для функций rand() и srand()
  3. #include <ctime>
  4.  
  5. using namespace std;
  6.  
  7. int getRandomNumber(int min, int max)
  8. {
  9.     static const double fraction = 1.0 / (static_cast<double>(RAND_MAX) + 1.0);
  10.     return static_cast<int>(rand() * fraction * (max - min + 1) + min);
  11. }
  12.  
  13. int main()
  14. {
  15.     srand(static_cast<unsigned int>(time(0)));
  16.     rand();
  17.  
  18.     int matches = 100;
  19.     int subByCom;  // столько отнимает компьютер
  20.     int subByUser; // столько отнимает юзер
  21.     cout << "The game has begun." << "\n";
  22.     while(true)
  23.     {
  24.         subByCom = getRandomNumber(0, 10);
  25.         matches -= subByCom;
  26.         if(matches <= 0)
  27.         {
  28.             cout << "You win" << "\n";
  29.             break;
  30.         }
  31.  
  32.         cout << "Computer has made his turn. Now your turn. Enter a number from 0 to 10 : ";
  33.         cin >> subByUser;
  34.         matches -= subByUser;
  35.         if(matches <= 0)
  36.         {
  37.             cout << "You lose" << "\n";
  38.             break;
  39.         }
  40.  
  41.     }
  42.  
  43.  
  44.     return 0;
  45. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top