title: How to code 'switch' statements concisely to guess a number the user is thinking of
body: <p>I'm studying Bjarne Stroustrup's "Programming Principles and Practice Using C++". In Chapter 4 you are to create a game where the user thinks of an integer between 1 to 100 and the computer should ask questions to guess the answer. Ideally you should have the answer within 7 questions. My intuition is to ask half of each possible range repeated multiple times, e.g. at first when the range possibilities are 1 to 100 ask the question "Is the number you are thinking of greater or equal to 50?".</p>
  
  <p>Here is a part of my solution showing how I was nesting the switch statements:</p>
  
  <pre><code>char user_answer;
  
  cout &lt;&lt; "Is the number &gt;= 50? Answer "yes" or "no" by inputting 'y' or 'n': \a\n";
  cin &gt;&gt; user_answer;
  switch (user_answer)
  {
  case 'y':
      cout &lt;&lt; "Is the number &gt;= 75? Answer "yes" or "no" by inputting 'y' or 'n': \a\n";
      cin &gt;&gt; user_answer;
      switch (user_answer)
      {
      case 'y':
          cout &lt;&lt; "Is the number &gt;= 87? Answer yes or no (you get the idea): \a\n";
          cin &gt;&gt; user_answer;
          switch (user_answer)
          {
  </code></pre>
  
  <p>While hypothetically creating every eventual yes and no case would result in accurate logic, this code is difficult to maintain and create. Should I be attempting this with a while loop? Functions? I attempted a 'for' loop but I could not implement repetition of the logic explained above.</p>