
[英]"identifier "hInstance" is undefined" and "too few arguments in function call"
[英]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);
}
main
之前宣布game
game
函数需要2个参数,而你只传递一个(在main
) rand()
你需要#include <cstdlib>
。 #include <time.h>
并将srand (time(NULL))
放在main
的开头。 game
原型,要么在调用它之前定义它。 game
有两个参数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.