Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib> // для функций rand() и srand()
- #include <ctime>
- using namespace std;
- int getRandomNumber(int min, int max)
- {
- static const double fraction = 1.0 / (static_cast<double>(RAND_MAX) + 1.0);
- return static_cast<int>(rand() * fraction * (max - min + 1) + min);
- }
- int main()
- {
- srand(static_cast<unsigned int>(time(0)));
- rand();
- int matches = 100;
- int subByCom; // столько отнимает компьютер
- int subByUser; // столько отнимает юзер
- cout << "The game has begun." << "\n";
- while(true)
- {
- subByCom = getRandomNumber(0, 10);
- matches -= subByCom;
- if(matches <= 0)
- {
- cout << "You win" << "\n";
- break;
- }
- cout << "Computer has made his turn. Now your turn. Enter a number from 0 to 10 : ";
- cin >> subByUser;
- matches -= subByUser;
- if(matches <= 0)
- {
- cout << "You lose" << "\n";
- break;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement