猜 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: "; 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; } }
原文地址:https://www.cnblogs.com/wuOverflow/p/4648821.html