title: A recursive function to print each new position to console?
body: <p>this is a c++ homework question so I would very much appreciate some guidance in the right direction. 
  The problem asks for input of a positive integer to represent position. If the initial position is even, the new position is d/2, and if odd the new position is 3*d+1, and this continues until position is one. </p>
  
  <p>Ex: Enter a positive integer: 11</p>
  
  <p>The OJP for 11: 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1</p>
  
  <p>This is some code that I got to work by iteration:</p>
  
  <pre><code>#include "stdafx.h"
  #include &lt;iostream&gt;
  using namespace std;
  
  int ollyjumppattern(int d)
  {
      if (d == 1)
      {
          return 1;
      }
      else if (d % 2 == 0)
      {
          return (d / 2);
      }
      else
      {
          return (3 * d + 1);
      }
  }
  
  
  int main()
  {
      int target;
      cout &lt;&lt; "Enter a positive integer: ";
      cin &gt;&gt; target;
      cout &lt;&lt; "The OJP for " &lt;&lt; target &lt;&lt; ": ";
  
      if (target == 1)
      {
          cout &lt;&lt; "1";
      }
      else
      {
          cout &lt;&lt; target;
          while (target != 1)
          {
              cout &lt;&lt; " " &lt;&lt; ollyjumppattern(target) &lt;&lt; " ";
              target = ollyjumppattern(target);
          }
          cout &lt;&lt; endl;
      }
      return 0;
  }
  </code></pre>
  
  <p>And this is what I have so far for recursive:</p>
  
  <pre><code>#include "stdafx.h"
  #include &lt;iostream&gt;
  using namespace std;
  
  int ollyjumppattern(int d)
  {
      if (d == 1)
      {
          cout &lt;&lt; "1";
          return 1;
      }
      else if (d % 2 == 0)
      {
          int result = ollyjumppattern(d/2);
          cout &lt;&lt; result &lt;&lt; " ";
          return result;
      }
      else
      {
          int result = ollyjumppattern(3*d+1);
          cout &lt;&lt; result &lt;&lt; " ";
          return result;
      }
  }
  
  
  int main()
  {
      int target;
      cout &lt;&lt; "Enter a positive integer: ";
      cin &gt;&gt; target;
      cout &lt;&lt; "The OJP for " &lt;&lt; target &lt;&lt; ": ";
  
      if (target == 1)
      {
          cout &lt;&lt; "1";
      }
      else
      {
          cout &lt;&lt; ollyjumppattern(target);
          cout &lt;&lt; endl;
      }
      return 0;
  }
  </code></pre>
  
  <p>This code crashes when I try to run it
  I would very much appreciate any tips </p>