标识符未初始化

时间:2015-10-14 22:49:08

标签: c++ syntax-error

在这里做学校项目并遇到问题 我的程序是支持用户猜测一个47的数字,如果他们错了,他们总共有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

1 个答案:

答案 0 :(得分:4)

您忘记初始化GuessNum

int GuessNum = 0;
             ^^^

此外,while条件中的逗号不符合您的想法,您的意思是&&在C ++中是“和”。