我收到一个错误,说猜测没有在 main.xml 中定义。这是怎么回事?prog被设计成一个猜谜游戏
while 只是因为 main 中定义的猜测而停止,但这使计算机要求输入未经测试的输入。
#include <cstdlib>
#include <iostream>
#include <ctime>
using namespace std;
int nextGuess();
int main()
{
srand(time(0));
int number = rand() % 100 + 1;
cout <<" --GUESSING GAME-- \n You are to enter numbers, trying to guess rthe computer's number"<< endl;
int guess = nextGuess();
do
{
int guess = nextGuess();
if (guess > number)
cout <<"Your guess is to high."<< endl;
if (guess < number)
cout <<"Your guess is too low."<< endl;
if (guess == number)
cout <<"Good job, that's the number!"<< endl;
}
while (guess != number);
system("pause");
}
int nextGuess()
{
int guess = 0;
cout <<"Please enter a number:";
cin >> guess;
return guess;
}
** Id 粘贴 c 提示,但不会复制。