35657

Untitled

Jul 15th, 2023
912
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.16 KB | None | 0 0
  1. #include <string>
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. int cast() {
  7.     int a = rand() % 6 + 1;
  8.     int b = rand() % 6 + 1;
  9.     cout << a << ", " << b << endl;
  10.     return a + b;
  11. }
  12.  
  13. void game() {
  14.     srand(time(0));
  15.     int computer_glasses = 0;
  16.     int person_glasses = 0;
  17.     int first = rand() % 2;
  18.  
  19.     if (first == 0) {
  20.         cout << "Первым бросает компьютер" << endl;
  21.     }
  22.     else {
  23.         cout << "Первым бросает человек" << endl;
  24.     }
  25.  
  26.     for (int i = 1; i <= 10; i++) {
  27.         if (i % 2 != 0 && first == 0 || i % 2 == 0 && first == 1) {
  28.             cout << "Бросок компьютера: ";
  29.             computer_glasses += cast();
  30.         }
  31.         else {
  32.             cout << "Бросок человека: ";
  33.             person_glasses += cast();
  34.         }
  35.     }
  36.     cout << "Компьютер: " << computer_glasses << "   " <<  "Человек: " << person_glasses << endl;
  37.  
  38.     if (computer_glasses > person_glasses) {
  39.         cout << "Победил компьютер!" << endl;
  40.     }
  41.     else if (computer_glasses < person_glasses) {
  42.         cout << "Победил человек!" << endl;
  43.     }
  44.     else {
  45.         cout << "Ничья!" << endl;
  46.     }
  47. }
  48.  
  49. int main() {
  50.     setlocale(LC_ALL, "ru");
  51.     game();
  52. }
  53.  
Advertisement
Add Comment
Please, Sign In to add comment