正在這裏做學校項目並遇到問題 我的程序支持用戶猜測一個數字是47,如果他們得到了錯誤,他們總共5次嘗試5次。如果仍然沒有得到它,程序將退出。如果他們得到了答案,將會有一條消息說明有多少次嘗試才能得到答案。 因此,我必須有一個標識符的嘗試次數。但C++說,我沒有初始化標識符。請幫助標識未被初始化
#include <iostream>
using namespace std;
int main()
{
int intSecretNum = 47;
int intGuess;
int GuessNum;
cout<< "Guess the secret number (between 0 and 100 inclusively): ";
cin>> intGuess;
while(intSecretNum != 47, GuessNum<= 5)
{
if(intGuess < intSecretNum)
cout << "Your Number is smaller than the secret number";
else if (intGuess > intSecretNum)
cout << "Your Number is bigger than the secret number";
GuessNum++;
if(GuessNum>5)
cout << "Sorry, you have used up all your quota (5 times)! The secret number is "<<intSecretNum;
cout << "program terminated." <<endl;
}
cout<< "You have used "<<GuessNum <<" to guess te secret number which is " <<intSecretNum<<".";
cout<<"program terminated."<<endl;
return 0;
}
請幫= d
編譯器是正確的。 'GuessNum'沒有初始化。此外,'while(intSecretNum!= 47,GuessNum <= 5)'不正確。使用'&&'代替逗號。 – owacoder