I was wondering how i would go about and make an AI that actually guesses a number that i pick by whether i say "Too high" or "Too low".
Here is an example of code from a guessing game.
Code:// Guess My Number
// The classic number guessing game
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
srand(time(0)); // seed random number generator
int theNumber = rand() % 100 + 1; // random number between 1 and 100
int guess= rand() % 100 + 1;//Computer guesses number between 1 and 100
int tries = 0;
cout << "\tWelcome to Guess My Number\n\n";
do
{
cout << "Enter a guess: "<<guess;
++tries;
if (guess > theNumber)
cout << "Too high!\n\n";
if (guess < theNumber)
cout << "Too low!\n\n";
} while (guess != theNumber);
cout << "\nThat's it! You got it in " << tries << " guesses!\n";
system("pause");
return 0;
}