Original Post
My book wanted me to write a piece of code that would have the player pick a number, and then have the computer try to guess it. I did so successfully, but i cant get the computer to recognize its previous guesses. Could someone help me to solve the problem?
// Guess MY NUmber
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
cout << "\tWelcome to Guess MY NUmber 2.0\n";
cout << "\tIn this version, the computer has to guess YOUR Number\n\n";
char yesNo;
int theNumber;
do
{
cout << "Please Input a number between (1 - 100): ";
cin >> theNumber;
if((theNumber < 1) || (theNumber > 100))
{
cout << "Between 1 and 100 please\n\n";
continue;
}
cout << "\nIs " << theNumber << " the number you really want to choose? (y/n) : ";
cin >> yesNo;
}while (yesNo != 'y');
srand(time(0));
int highGuess = 100;
int lowGuess = 1;
int tries = 0;
int guess;
do
{
guess = ((rand() % highGuess) + lowGuess);
++tries;
cout << guess << " ";
if (guess > theNumber)
{
cout << "Too High\n";
if (guess < highGuess)
{ highGuess = guess;
continue;
}
else
continue;
}
if (guess < theNumber)
{
cout << "Too Low\n";
if (guess > lowGuess)
{
lowGuess = guess;
continue;
}
else
continue;
}
}while (guess != theNumber);
cout << "\nThe Computer Got the number in " << tries << " tries";
std::cin.ignore(std::cin.rdbuf()->in_avail() +3);
return 0;