title: c++ beginner generate random numbers using while loop
body: <p>generate 10 random integers in the range [- 50, 50 ], then outputs the largest among them.  What i have tried is </p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;ctime&gt;
  
  using namespace std;
  
  int main(){
  
      int startNum = -50;
      int endNum = 50;
      int rand = 0;
      int result = 0;
  
      srand(time(0));
      rand = (rand % (endNum - startNum +1 ) +startNum);
      int i = 0;
      int largestNum = 0;
  
      while (i &lt;9){
          result = rand; 
          if (result &gt; largestNum){
              largestNum = rand;
                  i++;
          }
  
      }
          cout &lt;&lt; "the largest number is " &lt;&lt; largestNum &lt;&lt; endl; 
  
      system("pause");
      return 0;
  }
  </code></pre>