I'm trying to create a little text game that has the computer guess the number a user inputs. The problem is that the computer keeps guessing the same number an infinite amount of times.
Here's the code :
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
srand(static_cast<unsigned int>(time(0))); //seed random number generator
int CompGuess = rand() % 100 + 1; //random # bet. 1 and 100
int tries = 0;
int secretnumber;
cout << "\tWelcome to Guess My number V 1.1" << endl;
cout << "\nPlease input a number: ";
cin >> secretnumber;
cout << "\nNow lets see how long the AI takes to guess your number....hehehehe!!!" << endl;
do
{
cout << "Hmmm is your number " << CompGuess << " ???";
++tries;
if (CompGuess != secretnumber)
{
cout << "Try again!";
}
else
{
cout << "\nThat's it! You got it in " << tries << " guesses!\n";
}
}while (CompGuess != secretnumber);
}