值没有正确递增

And*_*w B 1 c++

此应用程序的目的是模拟大量的掷骰子游戏.我有另一个版本,它玩一个游戏,要求用户输入和输出信息.此版本的目的是仅在10,000次游戏后显示结果.结果是房子赢了多少场比赛,玩家赢了多少场比赛以及每场比赛的平均掷骰数.我还没有实现滚动,因为我想让游戏首先正确递增.

当我执行这个时会发生什么是一个数字墙(这是由于cout << playerwintotal;)并且是故意的,但数字重复3-4次,直到循环已经超过10,000次.

即.1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 5 5 5等

最终结果通常是这样的:

经过10,000次掷骰子游戏后,
玩家赢得了2502场比赛.
这座房子赢了3625场比赛.

我不确定如何解决这个问题,因为我可以说一切都是应该的,尽管这只是我第四天的C++.

#include <iostream>
#include <string>
#include "randgen.h"

using namespace std;

const int MAX_PLAYS = 10000;

int main() {

    int roll;
    RandGen rg;
    int die1 = rg(6) + 1;
    int die2 = rg(6) + 1;
    int point;
    int total = die1 + die2;
    bool playerwin;
    bool housewin;
    int playerwintotal = 0;
    int housewintotal = 0;

    for (int i = 0; i < MAX_PLAYS; ++i) {
        roll = 1;

        if (roll == 1 && (total == 7 || total == 11)) {
            playerwin = true;
            ++playerwintotal;
        }
        if (roll == 1 && (total == 2 || total == 3 || total == 12)) {
            housewin = true;
            ++housewintotal;
        }
        if (roll == 1 && (total != 2 || total != 3 || total != 12)) {
            point = total;
            playerwin = false;
            housewin = false;
        }

        die1 = rg(6) + 1;
        die2 = rg(6) + 1;
        total = die1 + die2;
        ++roll;
        if (total == point) {
            playerwin = true;
            ++playerwintotal;
        }
        if (total == 7) {
            housewin = true;
            ++housewintotal;
        }

        cout << playerwintotal;

    }
    cout << "After " << MAX_PLAYS << " games of craps:\n" << "Player won "
            << playerwintotal << " times\n" << "The house won " << housewintotal
            << " times\n";

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

Seb*_*zus 5

total != 2 || total != 3 || total != 12
Run Code Online (Sandbox Code Playgroud)

总是如此.你可能意味着

total != 2 && total != 3 && total != 12
Run Code Online (Sandbox Code Playgroud)