#include /* The rules: The computer thinks of a number between 1 and 1000, and then tries to guess it. Unlike a with human player, we can program the computer to make real guesses without making use of the fact that it really knows the right answer already. The computer will always get it right in 10 tries or fewer */ string guess(int min, int max, const int secret) { cout << "The secret number is " << secret << "\n"; int count = 0; while (count < 8) { const int middle = (min + max) / 2; count = count + 1; cout << count << " I guess " << middle << "\n"; if (middle == secret) return "I won!!!\n"; else if (middle > secret) max = middle-1; else if (middle < secret) min = middle+1; } cout << "game over.\n"; return "we lost.\n"; } void main() { cout << "Result: " << guess(1, 1000, random_in_range(1, 1000)); }