title: Trouble Implementing nested loops into a recursive solution
body: <p><strong>Non-Recursive Code</strong></p>
  
  <p>Here is the code I am trying to convert into a recursive solution.</p>
  
  <pre><code>int main()
  {
      int number[3];
      for (number[0]=0; number[0] &lt;= 9; number[0]++) 
      {   
          for (number[1]=0; number[1] &lt;= 4; number[1]++)
          {
              for (number[2]=0; number[2] &lt;= 9; number[2]++)
              {
                  std::cout &lt;&lt; number[0] &lt;&lt; number[1] &lt;&lt; number[2] &lt;&lt; std::endl; 
              }
          }
      }
      std::cout &lt;&lt; "Press any key to continue";
      std::cin.ignore();
      return 0;
  }
  </code></pre>
  
  <p>The output of this code can be found here <a href="http://pastebin.com/f20X3gT3" rel="nofollow">http://pastebin.com/f20X3gT3</a>.</p>
  
  <p><strong>Recursive Attempt</strong></p>
  
  <p>Here is my failed attempt at replicating the above algorithm into a recursive solution.  It compiles without any errors but it does not give the same results as the above Non-Recursive solution does.</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  const int NumberLength = 3;
  int number[3];
  int element;
  
  void generateFormula(const int Length) {
      if(Length == 0) {
          for (int n = 0; n &lt;= NumberLength; ++n) {
              std::cout &lt;&lt; number[n];
          }
          std::cout &lt;&lt; std::endl;
          return; 
      }
      if(element%2==0) {
          for(number[element]=0; number[element] &lt;= 9; number[element]++);
              generateFormula(Length-1);
      }
      else {
          for(number[element]=0; number[element] &lt;= 4; number[element]++);
              generateFormula(Length-1);
      }
      element++;
  }
  
  int main()
  {
      for (int i = 0; i &lt;= NumberLength; ++i)
          generateFormula(i);
  
      std::cout &lt;&lt; "Press any key to continue";
      std::cin.ignore();
      return 0;
  }
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>0000 
  10000
  10501
  10500
  </code></pre>