title: How to limit the amount of times a while loop runs? C++
body: <pre><code>#include &lt;iostream&gt;
  #include &lt;cmath&gt;
  #include &lt;ctime&gt;
  #include &lt;cstdlib&gt;
  using namespace std;
  
  int main( )
  {
      int number1; 
      int number2;
      int answer; 
      srand(time(0));
      number1= rand()%10+1;
      number2= rand()%10+1;
      cout&lt;&lt; number1 &lt;&lt;" + " &lt;&lt; number2 &lt;&lt; endl; 
  
      cin&gt;&gt; answer; 
  
      if(number1 + number2 == answer) {
          cout &lt;&lt; "correct"&lt;&lt; endl; 
  
      }
      else {
          cout &lt;&lt; "Incorrect" &lt;&lt; endl; 
          cout &lt;&lt; "Answer:" &lt;&lt; number1 + number2;
      }
  
      while(number1+number2==answer) {
  
      }
      return 0;
  }
  </code></pre>
  
  <p>I'm trying to make a program that asks the user a simple math question. In this final step, the user has to answer three questions correctly and then the loop will end. </p>
  
  <p>If the user answers incorrectly, the loop will continue. My question is how can I do this? I'm confused on how to set up the loop in order for the program to work correctly.</p>