猜 1-100 内的数字,范围逐渐缩小
void guessNumber()
{
uniform_int_distribution<unsigned> creator1To100(1, 100);
default_random_engine engin;
auto answer = creator1To100(engin);
unsigned low = 1;
unsigned high = 100;
while (true){
cout << "Guess a number:\n";
unsigned guess = 1;
cin >> guess;
if(guess == answer){
cout << "Yeah, Binggo!!!!";
return;
}
uniform_int_distribution<unsigned> lowBoundCreator(low, answer - 1);
low = lowBoundCreator(engin);
uniform_int_distribution<unsigned> highBoundCreator(answer + 1, high);
high = highBoundCreator(engin);
cout << "The number between the " << low << " and " << high << endl;
}
}