### 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:
 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697`` ``````#include #include #include #include using namespace std; int main() { srand(static_cast(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 "<>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 "<>nothing; }``````
Is there any specific problem with it?
Topic archived. No new replies allowed.