Binary search guess game in C++
I don't know, if you can understand all my code, but I would implement the task this way:

#include &lt;iostream&gt;
#include &lt;random&gt;
#include &lt;string&gt;

enum class CompareAnswer { LESS, LESS_OR_EQUAL, GREATER, GREATER_OR_EQUAL };
enum class TruthAnswer { YES, NO };

CompareAnswer ask_user_compare(int compare_with) {
  static auto randfn = []() -&gt; bool {
    static auto dist = std::uniform_int_distribution&lt;&gt;(0, 1);
    static auto gen = std::default_random_engine();
    return static_cast&lt;bool&gt;( dist(gen) );
  };

  char user_input;
  std::cout &lt;&lt; "Is your number ";

  if (randfn()) {
    std::cout &lt;&lt; "less than " &lt;&lt; compare_with &lt;&lt; "? [y|n]\n";
    std::cin &gt;&gt; user_input;
    if (user_input == 'y')
      return CompareAnswer::LESS;
    if (user_input == 'n')
      return CompareAnswer::GREATER_OR_EQUAL;
    throw std::runtime_error("invalid answer");
  };

  std::cout &lt;&lt; "greater than " &lt;&lt; compare_with &lt;&lt; "? [y|n]\n";
  std::cin &gt;&gt; user_input;
  if (user_input == 'y')
    return CompareAnswer::GREATER;
  if (user_input == 'n')
    return CompareAnswer::LESS_OR_EQUAL;
  throw std::runtime_error("invalid answer");
};

TruthAnswer ask_user_is(int number) {
  std::cout &lt;&lt; "Is your number " &lt;&lt; number &lt;&lt; "? [y|n]\n";
  char user_input;
  std::cin &gt;&gt; user_input;

  if (user_input == 'y')
    return TruthAnswer::YES;
  if (user_input == 'n')
    return TruthAnswer::NO;
  throw std::runtime_error("invalid answer");
}

int guess_number(const int min, const int max) {
  // std::cout &lt;&lt; "\ndebug: min=" &lt;&lt; min &lt;&lt; " max=" &lt;&lt; max &lt;&lt; "\n";

  const int median = (min + max) / 2;  // (77+78)/2  =77

  if (median == min) {
    return ask_user_is(min) == TruthAnswer::YES ? min : max;
  };

  switch (ask_user_compare(median)) {
    case CompareAnswer::GREATER:
      return guess_number(median + 1, max);
    case CompareAnswer::GREATER_OR_EQUAL:
      return guess_number(median, max);
    case CompareAnswer::LESS:
      return guess_number(min, median - 1);
    case CompareAnswer::LESS_OR_EQUAL:
      return guess_number(min, median);
    default:
      throw std::logic_error("need case for some of 'enum Answer' ");
  };
};

int main() {
  constexpr int MIN = 0;
  constexpr int MAX = 10000;

  std::cout &lt;&lt; "Choose a number from " &lt;&lt; MIN &lt;&lt; " to " &lt;&lt; MAX &lt;&lt; "\n";
  int number;
  std::cin &gt;&gt; number;
  if(number &lt; MIN || number &gt; MAX) throw std::runtime_error("Invalid number");

  int guessed = guess_number(MIN, MAX);
  std::cout &lt;&lt; "Your number is: " &lt;&lt; guessed &lt;&lt; "\n";
}


Even though guess_number is recursive function, probability of stack overflow extremely low (cause log(N) complexity). Asking user again instead of throwing exception may be good idea too. 

Also:
Generally forget about srand, use &lt;random&gt; instead (srand is only for homework)