Number Guessing program

Hey this is a program I've been working on. I was just looking for some input and tips/advice to improve it.

You think of a number between 1 and 100. The computer tries to guess it based off user input in which you tell it too low, too high or correct.

Here's what I have so far:
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>

using namespace std;

int main()
{
    srand(static_cast<unsigned int>(time(0)));  //seed random number generator

	int compGuess = rand() % 100 + 1;  // random number between 1 and 100
	int tries = 0;
	int answer;
	bool guess;
	int lo=1;
	int hi=100;
	char nothing;
	bool test;

	cout<<"\tWelcome to Guess your Number!\n";
	cout<<"\tThink of a number between 1 and 100.\n\n";

	do
	{
	    cout<<"My guess is "<<compGuess <<"\n";
	    cout<<"Is this: \n";
	    cout<<"1: Too low\n";
	    cout<<"2: Too high\n";
	    cout<<"3: correct\n";
	    cout<<"Your input: ";
	    cin>>answer;
	    cout<<"\n";
	    ++tries;
	    guess = false;

        while(cin.fail() || answer < 1 || answer > 3)
        {
            cout<<"Please enter a valid input!\n";
            cout<<"Your input: ";
            cin.clear();
            cin.get();
            cin>>answer;
            cout<<"\n";
        }

        if (answer !=3 && (hi==lo || hi-lo==1))
        {
            cout<<"You cheated. I quit!\n";
            guess=true;
        }

        else
        {
            switch(answer)
            {
            case 1: //too low
                lo=compGuess+1;
                if((hi-lo+1)==0)
                    lo=compGuess;
                compGuess=rand()%(hi-lo+1)+lo;
                while(compGuess==lo)
                {
                    compGuess=rand()%(hi-lo+1)+lo;
                    if(hi==lo)
                        break;
                }
                break;

            case 2: //too hi
                hi=compGuess-1;
                if((hi-lo+1)==0)
                    hi=compGuess;
                compGuess=rand()%(hi-lo+1)+lo;
                while(compGuess==hi)
                {
                    compGuess=rand()%(hi-lo+1)+lo;
                    if (hi==lo)
                        break;
                }
                break;

            case 3: //correct
                if(tries>1)
                    cout<<"I win! It only took me "<<tries<<" guesses!\n";
                if (tries==1)
                    cout<<"I win! It only took me 1 guess!\n";
                guess = true;
                break;
            }
        }

    }while(!guess);

cout<<"Type anything to exit!"<<endl;
cin>>nothing;
}
Is there any specific problem with it?
Topic archived. No new replies allowed.