title: C++ function only goes thru the for loop once
body: <p>so I've got integers <code>m</code> and <code>n</code> in my program, once you input the values it should create an array with values from <code>m</code> to <code>n</code> (for example <code>m = 1</code> and <code>n = 10</code>, it creates array <code>q</code> with values from 1 to 10). Then it looks in the array if there are any numbers that are equal to any two number sum that are squared (for example, in the array, number 2 is equal to 1 squared + 1 squared). The problem is the program only gives out the first found result, as an example let's take 1 and 10 again, it only out prints 2 = 1 * 1 + 1 * 1, it should go thru the for loop again and find out that 5 = 2 * 2 + 1 * 1 etc etc. Is it even possible to do with a function that begins with int?</p>
  
  <pre><code>    #include &lt;iostream&gt;
  using namespace std;
  
  
  int squared (int m, int n, int* M)
  {
      int result;
      for(int i= 0; i &lt; n; i++)
          for(int j= 0; j &lt; n; j++)
              for(int k= 0; k &lt; n; k++)
                  if( (M[i] == ( (M[j] * M[j]) + (M[k] * M[k]) ))) 
                  {
                      result = ( (M[j] * M[j]) + (M[k] * M[k]) );
                      cout &lt;&lt; result &lt;&lt; endl;
                      return result; // if success we return result
                  }
  
      return -1; 
  }
  
  int main ()
  {
      int n, m, size;
  
      do
      {
          cout &lt;&lt;"m: ";
          cin &gt;&gt; m;
          cout &lt;&lt; "n: ";
          cin &gt;&gt; n;
  
          if(n &lt;= 0 || m &lt;= 0)
              cout &lt;&lt;"You can't input an integer that is 0 or below: ";
  
          if(m &gt;= n)
              cout &lt;&lt; "n must be greater than m!" &lt;&lt; endl;
      }while (m &lt;= 0 || n &lt;= 0 || m &gt;= n);
  
      size = n - m; 
      int* M = new int[n - m]; 
  
  
      for(int i= 0, j = m; i &lt;= size; i++, j++)
          M[i] = j;
  
  
      for(int i = 0; i &lt;= size; i++)
          cout &lt;&lt; M[i] &lt;&lt; ", " ;
      cout &lt;&lt; endl;
  
  
      cout &lt;&lt; squared(m, n, M) &lt;&lt; endl;
  
  
      delete[] M;
  
      return 0;
  }
  </code></pre>