title: Can you help me with my recursive function?
body: <p>I have this simple function that I am calculating correctly, but my output statements are off. I have tried other places were the cout statement is commented, but not working.</p>
  
  <pre><code>int recursiveFunc(int n) {
      int val;    // value at nth sequence
  
  
      //cout &lt;&lt; "(" &lt;&lt; n &lt;&lt; ") = " &lt;&lt; val &lt;&lt; endl;
  
      if (n == 1 ) {      // base case 1
          val = -1;
          // outputs before function call
      }
      else if (n == 2) {  // base case 2
          val = -1;
          // outputs before function call
      }
      else {      // recursive case
          //cout &lt;&lt; "(" &lt;&lt; n &lt;&lt; ") = &lt;&lt; val &lt;&lt; endl;
          val = 2*(recursiveFunc(n-1) + recursiveFunc(n-2));
          cout &lt;&lt; "(" &lt;&lt; n &lt;&lt; ") = " &lt;&lt; val &lt;&lt; endl;   // not sure where to put cout statement
  
      }
  
      return val;
  }
  </code></pre>
  
  <p>I am looking for an output like (for example n = 5):</p>
  
  <pre><code>(1) = -1
  (2) = -1
  (3) = -4
  (4) = -10
  (5) = -28
  </code></pre>
  
  <p>currently, my output looks like: </p>
  
  <pre><code>(1) = -1
  (2) = -1
  (3) = -4
  (4) = -10
  (3) = -4    // here an nth term is displayed twice
  (5) = -28
  </code></pre>