Auto guess program problem

Previously I made a program which allowed the computer to generate a number between 1-100 and I had to guess it.

But now I'm making program which will allow me to enter a number and then computer will have to guess it. I don't know what I'm doing wrong. So please help me with this.

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
37
38
39
40
41
42
43
44
45
#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;

int main()
{
    int GuessNumber;

    cin >> GuessNumber;

    cout << "Guess the number you dummy.\n";

    srand(time(NULL));
    int number = rand() % 100;

    while (true)
    {
        if (number < 0)
          {
              cout << "Too low.\n";

          }

         else if (number > 100)
          {
             cout << "Too big.\n";
          }

          else if (number == GuessNumber)
          {
             cout << "Your guess is correct.\n";
          }

         else
          {
             cout << "Your guess is incorrect";
          }
    }




    return 0;
}
Line 19: number will always be between 0 and 99. What's the point of checking if it's less than 0?

Line 25: Likewise, number will never be greater than 100.

Line 17: Program will loop forever outputting the same message. You never prompt for another guess.

Number guessing games such as this usually determine if the number is too high or too low then set new limits of the guess. e.g. If the computer's first guess is 75 and that is too high, then you should limit the computer's next guess to numbers between 0 and 74. No point in letting the computer guess numbers > 75 since we alreay know that is too high.
Topic archived. No new replies allowed.