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