Original Post
Hey, im new to C++ and learn it through a book, anyways iv been set a task to rewrite a game "guess my number" where i have to make the computer guess the users number but i get stuck in a loop and i cant see why its really bugging me and i know its going to be the silliest thing...
[size="1"]// Guess My Number
// The classic number guessing game
[size="1"]#include
#include
#include
[size="1"]using namespace std;
[size="1"]int main()
{
srand(time(0)); // seed random number generator
int theNumber;
cout << "\nPlease enter a number between 1-100 for the computer to guess: ";
cin >> theNumber;
int tries = 0, computerGuess;
do
{
int computerGuess = rand() % 100 + 1;
cout << "The computers guess: ";
cout << computerGuess;
++tries;
[size="1"] if (computerGuess > theNumber)
cout << " Too high!\n\n";
if (computerGuess < theNumber)
cout << " Too low!\n\n";
}while (computerGuess != theNumber);
[size="1"] cout << "\nThe computer got your number in " << tries << " guesses!\n";
[size="1"] return 0;
}
[size="1"]// Guess My Number
// The classic number guessing game
[size="1"]#include
#include
#include
[size="1"]using namespace std;
[size="1"]int main()
{
srand(time(0)); // seed random number generator
int theNumber;
cout << "\nPlease enter a number between 1-100 for the computer to guess: ";
cin >> theNumber;
int tries = 0, computerGuess;
do
{
int computerGuess = rand() % 100 + 1;
cout << "The computers guess: ";
cout << computerGuess;
++tries;
[size="1"] if (computerGuess > theNumber)
cout << " Too high!\n\n";
if (computerGuess < theNumber)
cout << " Too low!\n\n";
}while (computerGuess != theNumber);
[size="1"] cout << "\nThe computer got your number in " << tries << " guesses!\n";
[size="1"] return 0;
}