Need help with guessing game.

Hey guys,

I'm making the "guess my number" game most of you have probably seen before. I am trying to get the computer to remember all previous guesses its already tried so it doesn't repeat any.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
cout << "Enter your number: ";
      cin >> playerNumber;

	do
	{
	int cpuguess = rand() % (cpuGuessHigh - cpuGuessLow + 1) + cpuGuessLow;
	cout << "\nCpu thinks: " << cpuguess << endl; 
	++tries;


        if (cpuguess > playerNumber)
	{
	cout << "Too high!\n\n";
	cpuGuessHigh = cpuguess;
	cpuSuccess = false;


	}
	else
	   if (cpuguess < playerNumber)
	   {
	   cout << "Too low!\n\n";
	   cpuGuessLow = cpuguess;
	   cpuSuccess = false;

	   }
	   else
              {
	      cout << "That's right! You guessed it in ";
              cout << tries << " guesses!\n";
	      cpuSuccess = true;
	      }



	      } while (cpuSuccess != true);


Any help would be appreciated.
you need an array which has the size of maximum tries where you can store the actual try.
You could use a vector of integers, then push back every cpu guess, then compare the next guess to the previous ones, if the is a match, randomize again.

Aceix.
Topic archived. No new replies allowed.