繁体   English   中英

创建一个飞镖游戏和两个错误出现“函数调用中的争论太少”和“游戏,未找到标识符”

[英]Creating a darts game and two errors come up “too few argurments in function call” and “game, identifier not found”

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

too few argurments in function call

game, identifier not found

我正在尝试创建一个分配游戏,让两个玩家“乔和sid”从301播放飞镖,没有双打只是一个公牛和一个数组中的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. 你需要在main之前宣布game
  2. game函数需要2个参数,而你只传递一个(在main
  3. 对于rand()你需要#include <cstdlib>
  4. 我还建议#include <time.h>并将srand (time(NULL))放在main的开头。
  1. 要么宣布game原型,要么在调用它之前定义它。
  2. 功能game有两个参数。

暂无
暂无

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

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