So i read the "Flush Cin" post at the top of the thread and it just flew right over my head. I have a simple if statement that uses int values to determine where to send the user. If the user enters a char value it shoots itself into an infinite loop... this is my code, please help and thanks =)
int game()
{
int guess;
system("cls");
cout << endl << "Start!" << endl;
srand(time(0));
int randomNumber = rand() % 100 + 1; // generate random number
int NUM = (randomNumber); // number between 1 and 100
bool Wdone = false;
do
{
cout << endl << "Your guess\n- ";
num_of_guesses++;
cin.clear();
cin >> guess;
system("cls");
if (guess == randomNumber)
{
cout << endl << "You got it! Congrats!" << endl;
Wdone = true;
break;
}
else if (guess >= randomNumber)
{
cout << endl << "Too High!" << endl;
current_score--;
Wdone = false;
continue;
}
else if (guess <= randomNumber)
{
cout << endl << "Too Low!" << endl;
current_score--;
Wdone = false;
continue;
}
} while (Wdone == false);