Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

C++ | Игра в кубик с другом.

Май
79
10
Пользователь
Что можно здесь добавить? p.s я начинающий в с++

C++:
#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;

int rollDice() {
    return rand() % 6 + 1;
}
int main() {
    srand(time(nullptr));


    int player1Score = 0;
    int player2Score = 0;

    cout << "Игра в кубик начинается!" << endl;

    while (player1Score < 100 && player2Score < 100) {
        cout << "Игрок 1, нажмите Enter, чтобы бросить кубик: ";
        cin.get();
        int roll1 = rollDice();
        cout << "Выпало: " << roll1 << endl;
        player1Score += roll1;
        cout << "Счет игрока 1: " << player1Score << endl;

        if (player1Score >= 100) {
            cout << "Игрок 1 победил!" << endl;
            break;
        }

        cout << "Игрок 2, нажмите Enter, чтобы бросить кубик: ";
        cin.get();
        int roll2 = rollDice();
        cout << "Выпало: " << roll2 << endl;
        player2Score += roll2;
        cout << "Счет игрока 2: " << player2Score << endl;

        if (player2Score >= 100) {
            cout << "Игрок 2 победил!" << endl;
            break;
        }
    }


    return 0;
}
 
Сверху