title: variable nested for loops
body: <p>I'm trying to figure out how I can use recursion to do n-level nested for loops.
  For example, if n=3, there would be 3 'levels'</p>
  
  <pre><code>for(z=0;z&lt;6;z++){
     for(y=0;y&lt;6;y++){
        for(x=0;x&lt;6;x++){
           if (z+y+x==f){
              //do something
           } 
        }
     }
  }
  </code></pre>
  
  <p>and so on.</p>
  
  <p>I can't seem to figure out how I would be able to place the if loop in the last for loop and how I can access the variables of previous for loops from the if statement. I know that the question of variable nested loops has been asked alot of times, and I have looked through all of them. But none seem to help me. </p>
  
  <p>Could someone present an easy way of using recursion to achieve this, keeping in mind that I'm still a beginner in c++, to point me in the right direction?</p>
  
  <p>The use case is as follows:</p>
  
  <blockquote>
    <p>Write a program to input the number of dice m. The program will output the total number of possible cases, the number of possible cases for each possible n and the n with the highest probability. Note: only one input m is read in. n is computed by the program </p>
    
    <p>Example if user enters m=2 then program should output</p>
    
    <p>The total number of possible cases is 36.<br/>
    The possibilities are  <br/>
    2  1 <br/>
    3  2 <br/>
    4  3 <br/>
    .<br/>
    .<br/>
    .<br/>
    12 1</p>
  </blockquote>