创建飞镖游戏并出现两个错误
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);
}
最佳答案
- 您需要申报
game
在main
之前 -
game
函数有 2 个参数,而您只传递一个参数(在main
中) - 你需要
#include <cstdlib>
对于rand()
. - 我也建议
#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/