title: C++ Looping user input until correct
body: <p>I am asking the user for input in the range of 0 - 127, if they don't put the correct value I want the program to keep asking them until they input a correct value.</p>
  
  <p>At the moment I have the following code in a class:</p>
  
  <pre><code>void setNoteNumber (int value)
  {
  
      number = value;
  
      while (value &lt; 0 || value &gt; 127) {
  
      std::cout &lt;&lt; "This number is not in the range of 0 - 127, please select a new value: ";
  
      }
  }     
  </code></pre>
  
  <p>It kind of works, apart from if they input the wrong value my console repeatedly displays the error message. If anyone can help me it would be greatly appreciated! </p>
  
  <p>Thanks!</p>