我的模拟没有运行或循环

时间:2018-05-13 14:24:10

标签: c loops if-statement random boolean

我必须回答以下问题:

在Puzzlevania的土地上,Aaron,Bob和Charlie争论其中一个是有史以来最伟大的益智游戏。为了一劳永逸地结束辩论,他们同意了对死的决斗。亚伦是一名可怜的射手,他的命中率仅为1/3。鲍勃有点好,并以1/2的概率命中他的目标。查理是一名专家射手,从未错过。击中意味着杀戮,并且击中的人掉出决斗。为了弥补他们的射击技巧的不公平性,决定参赛者将从Aaron开始,然后是Bob,然后是Charlie。这个循环会重复,直到有一个人站着。那个人会被记住是有史以来最伟大的益智游戏。

我目前有以下代码写道:

int puzzle_count = 0;                                   
double aaron_accuracy = 1.0 / 3.0;
double bob_accuracy = 1.0 / 2.0;
double charlie_accuracy = 1.0;
bool aaron_alive;
bool bob_alive;
bool charlie_alive;
double random;
double aaronwins = 0;
double bobwins = 0;
double charliewins = 0;
double aaron_percent = 0;
double bob_percent = 0;
double charlie_percent = 0;

printf("\n Who is the greatest puzzler of all time?");
while (puzzle_count < 10000) {
    aaron_alive = true;
    bob_alive = true;
    charlie_alive = true;
    while (((aaron_alive = true) && (bob_alive = true)) || 
        ((bob_alive = true) && (charlie_alive = true)) || 
        ((aaron_alive = true) && (charlie_alive = true))) {

        if (aaron_alive = true) {
            if (charlie_alive = true) {
                random = rand() % 100;
                if (random < aaron_accuracy * 100) {
                    charlie_alive = false;
                        if (random > aaron_accuracy * 100) {
                            charlie_alive = true;
                        }
                }
            }
            if (charlie_alive = false) {
                random = rand() % 100;
                if (random < aaron_accuracy * 100) {
                    bob_alive = false;
                        if (random > aaron_accuracy * 100) {
                            bob_alive = true;
                        }
                }
            }
        }
        if (bob_alive = true) {
            if (charlie_alive = true) {
                random = rand() % 100;
                if (random < bob_accuracy * 100) {
                    charlie_alive = false;
                        if (random > bob_accuracy * 100) {
                            charlie_alive = true;
                        }
                }
            }
            if (charlie_alive = false) {
                random = rand() % 100;
                if (random < bob_accuracy * 100) {
                    aaron_alive = false;
                        if (random > bob_accuracy * 100) {
                            aaron_alive = true;
                        }
                }
            }
        }
        if (charlie_alive = true) {
            if (bob_alive = true) {
                random = rand() % 100;
                if (random < charlie_accuracy * 100) {
                    bob_alive = false;
                        if (random > charlie_accuracy * 100) {
                            bob_alive = true;
                        }
                }
            }
            if (bob_alive = false) {
                random = rand() % 100;
                if (random < charlie_accuracy * 100) {
                    aaron_alive = false;
                        if (random > charlie_accuracy * 100) {
                            aaron_alive = true;
                        }
                }
            }
        }


        if (aaron_alive = true)
            aaronwins++;
        if (bob_alive = true)
            bobwins++;
        if (charlie_alive = true)
            charliewins++;

    }
    puzzle_count++;
}

if (aaronwins + bobwins + charliewins == 10000) {
    aaron_percent = aaronwins / 10000;
    bob_percent = bobwins / 10000;
    charlie_percent = charliewins / 10000;

    printf("\n  Aaron won %f/10000 or %.2f% of the time", aaronwins, aaron_percent);
    printf("\n  Bob won %f/10000 or %.2f% of the time", bobwins, bob_percent);
    printf("\n  Charlie won %f/10000 or %.2f% of the time", charliewins, charlie_percent);
}
return 0;

}

当我运行代码时,它不会返回错误或警告并打开但不会运行模拟。我已多次阅读该代码,似乎无法找到导致此问题的原因。

如果这是因为印刷错误,我提前道歉。这是我正在学习的第一门编程课程,我的代码编写和故障排除技巧并不是最好的。

0 个答案:

没有答案