1
所以,我必须从随机猜测游戏编写一个程序。该程序需要让玩家在1-100之间猜出一个数字。至少必须使用一个功能。它需要告诉玩家他们是否太低/高,要求他们再试一次,或者如果他们猜测,请让他们再次玩。C++随机数猜测游戏错误
我有几个我找不出来的错误。
44:错误: '诠释winlose' 重新声明为不同种类的符号的 9:错误:错误: 'G' 为在此范围内声明
的 '诠释winlose(int)的' 44先前的声明代码
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int winlose(int);
int main()
{
int g, n, x;
while (x!=0)
{
do
{
srand(time(NULL));
n = 1 + rand()%100;
cout<<"Welcome to the guessing game. I have a number between 1-100.
Can you guess it?"<<endl;
cout<<"Please enter your guess"<<endl;
cin>>g;
winlose(g);
} while (n!=0);
cout<<"Play again? Enter 0 for no, any other number for yes."<<endl;
cin>>x;
}
return 0;
}
int winlose(g)
{
if (g<n)
{
cout<<"Your guess is too low. Try again."<<endl;
cin>>g;
}
else if (g>n)
{
cout<<"Your guess is too high. Try again."<<endl;
cin>>g;
}
else (g=n)
{
cout<<"Congrats! You win. The number was "<<n<<endl;
n=0;
}
return g;
return n;
}
'INT winlose(G)'这不是有效的函数声明的语法 – Borgleader
'INT winlose(G)' - >'INT winlose (int g)' – HolyBlackCat
[离线主题]除非你真的知道你在做什么,否则只调用'srand' **一次**。 – NathanOliver