简体   繁体   English

无法弄清楚为什么我的变量不断恢复为零

[英]Can't figure out why my variable keeps reverting to zero

I am working on a project for school that is a console dice game. 我正在为学校做一个游戏机骰子游戏的项目。 A problem that I have is that when I try to get the dice to score themselves the score variable always reverts to zero instead of what it should be. 我遇到的一个问题是,当我尝试让骰子自己得分时,score变量总是恢复为零,而不是应为零。 I may just be completely overlooking something simple as I am new to C++, but maybe y'all can help. 我可能只是完全忽略了一些简单的事情,因为我刚接触C ++,但是也许你们都能帮上忙。

Here is my code for the scoring method: 这是我的评分方法代码:

void FindScoreNumbers()
{
    int scoreDie[6];
    int score = 0;
    bool isScoring = false;
    int flushCounter1 = 0;
    int flushCounter2 = 0;
    int flushCounter3 = 0;
    int flushCounter4 = 0;
    int flushCounter5 = 0;
    int flushCounter6 = 0;

    scoreDie[0] = castDie[0];
    scoreDie[1] = castDie[1];
    scoreDie[2] = castDie[2];
    scoreDie[3] = castDie[3];
    scoreDie[4] = castDie[4];
    scoreDie[5] = castDie[5];


    for (unsigned int i = 0; i < 6; ++i)
    {
        if (scoreDie[i] == 1)
        {
            score + 100;
            flushCounter1++;
            isScoring = true;

            if (flushCounter1 >= 3)
            {
                score + 800;
                isScoring = true;

            }
        }

        if (scoreDie[i] == 2)
        {
            flushCounter2++;
            if (flushCounter2 >= 3)
            {
                score + 200;
                isScoring = true;

            }
        }

        if (scoreDie[i] == 3)
        {
            flushCounter3++;
            if (flushCounter3 >= 3)
            {
                score + 300;
                isScoring = true;

            }
        }

        if (scoreDie[i] == 4)
        {
            flushCounter4++;
            if (flushCounter4 >= 3)
            {
                score + 300;
                isScoring = true;

            }
        }

        if (scoreDie[i] == 5)
        {
            score + 50;
            flushCounter5++;
            isScoring = true;

            if (flushCounter5 >= 3)
            {
                score + 400;
                isScoring = true;

            }
        }

        if (scoreDie[i] == 6)
        {
            flushCounter6++;
            if (flushCounter6 >= 3)
            {
                score + 600;
                isScoring = true;

            }
        }
    }

    if (isScoring = true)
    {
        std::cout << score << std::endl;    
    }
    else
    {
        std::cout << "FARKLE! You didn't roll any scoring die." << std::endl;
    }

} }

I'm sorry if this isn't formatted properly this is my first question here. 很抱歉,如果格式不正确,这是我的第一个问题。 By the way, castDie[6] is the array of rolled die from a different bit of code. 顺便说一句, castDie[6]是来自不同代码位的轧制模具的阵列。 I also know that it returns the score 我也知道它会返回分数

score + 800; should be score = score + 800; 应为score = score + 800; (same for all the others). (其他所有内容都相同)。

You can also shortcut with score += 800; 您也可以使用score += 800;捷径score += 800;

It should be: 它应该是:

score += 100;

This is shorthand for: 这是以下内容的简写:

score = score + 100;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM