c++ - 创建飞镖游戏并出现两个错误 "too few argurments in function call"和 "game, identifier not found"

标签 c++ function identifier

创建飞镖游戏并出现两个错误

too few argurments in function call

game, identifier not found

我正在尝试为一项任务创建一个游戏,让两个玩家“joe 和 sid”从 301 开始玩飞镖,没有 double ,只有公牛和数组中的 21 个数字,解决问题的任何帮助都是非常感谢,下面的代码有四个主要功能,每个功能都会降低分数,首先是 50 分(公牛),然后是 20 分,然后是单打,当分数达到 50 时,两名球员必须以公牛和任何不是公牛的分数结束, 被丢弃。

下面是我的代码,如有任何帮助,我们将不胜感激。

#include <iostream>
using namespace std;

int dartScores[] = {20, 1, 18, 4, 13, 6, 10, 15, 2, 17, 3, 19, 7, 16, 8, 11, 14, 9, 12, 5, 20};

void makeThrow( int &score );

int main () 
{
    int joeScore = 301;
    int sidScore = 301;

    for (int i = 0; i< 1000;i++){
    while( joeScore > 0 || sidScore > 0 )
    {
        //do a throw
        game( joeScore);
        game( sidScore);

    }
    // remember to reset the score value

    }


}
void makeThrow_50( int &score, int acc )
{
    if ( rand()%100 < acc )
    {
        score -= 50;
    }
    else
    {
        //select a random
        int missedScore = dartScores[ rand()%20 ];

        // Only reduce score when thrown score is less than remaining score
        if (missedScore > score)
        {
            // Valid dart, take from score
            score -= missedScore;
        }
        else
        {
            // Invalid throw - BUST
            //cout << " BUST ";
        }

        //if (score <0) score=0;
    }
}

void makeThrow_20( int &score, int acc )
{
    if ( rand()%100 < acc )
    {
        score -= 20;
    }
    else
    {
        //select a random
        int missedScore = dartScores[ rand()%20 ];

        // Only reduce score when thrown score is less than remaining score
        if (missedScore > score)
        {
            // Valid dart, take from score
            score -= missedScore;
        }
        else
        {
            // Invalid throw - BUST
            //cout << " BUST ";
        }

        //if (score <0) score=0;
    }
}

void makeThrow_Single( int &score, int acc )
{
    if ( rand()%100 < acc )
    {
        score -= 1;
    }
    else
    {
        //select a random
        int missedScore = dartScores[ rand()%20 ];

        // Only reduce score when thrown score is less than remaining score
        if (missedScore > score)
        {
            // Valid dart, take from score
            score -= missedScore;
        }
        else
        {
            // Invalid throw - BUST
            //cout << " BUST ";
        }

        //if (score <0) score=0;
    }
}

void makeThrow_bull( int &score, int acc )
{
    if ( rand()%100 < acc )
    {
        score -= 50;
    }
    else
    {
        //select a random
        int missedScore = dartScores[ rand()%20 ];

        // Only reduce score when thrown score is less than remaining score
        if (missedScore > score)
        {
            // Valid dart, take from score
            score -= missedScore;
        }
        else
        {
            // Invalid throw - BUST
            //cout << " BUST ";
        }

        //if (score <0) score=0;
    }
}



int game(int& score, int acc) {
    if (score >= 100)
        makeThrow_50(score, acc);
    else if (score >= 70)
        makeThrow_20(score, 80);
    else if (score >= 51)
        makeThrow_Single(score, 80);
    else 
        makeThrow_bull(score, 80);

}

最佳答案

  1. 您需要申报 gamemain 之前
  2. game函数有 2 个参数,而您只传递一个参数(在 main 中)
  3. 你需要#include <cstdlib>对于 rand() .
  4. 我也建议 #include <time.h>并放置 srand (time(NULL))main的开头.

关于c++ - 创建飞镖游戏并出现两个错误 "too few argurments in function call"和 "game, identifier not found",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15566407/

相关文章:

c++ - Boost线程、Posix线程和STD线程,为什么它们提供不同的性能?

c++ - 在 C++ 中使用 memcpy 将结构写入 char 数组

sql - 使用SQL计算GPA,报 "Invalid Identifier"错误

c++ - c++ 中的命名空间和标识符与 dllexport

linux - 如何识别长时间运行的进程是否死亡?

c++ - GCC 和自定义指针中 libstdc++ 的 basic_string 实现

c++ - 推荐任何流行的 c++ 代码静态检查工具吗?

function - 如何动态创建在父作用域中可访问的功能?

Python 单行调用函数列表

python - Firebase 函数 gen2 python init 不起作用