I am getting an error saying that guess isn't defined in main. whats going on? the prog is designed to be a guessing game
The while is only stopping because of the guess defined in main, but that makes the computer ask fore an input that isn't tested.
#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 paste the c prompt but it wont copy.