How can I store the fibonacci sequence in a vector during each recursive call? #include &lt;iostream&gt;
#include &lt;vector&gt;

void getUserNum(int &amp;);
int rFib(int n);
void dispSeq(std::vector&lt;int&gt; &amp;vRef);

int main()
{
    int userNum;
    getUserNum(userNum);
    rFib(userNum);  
    return 0;
}

void getUserNum(int &amp;refVal)
{
    std::cout &lt;&lt; "Enter a positive integer:\n";
    std::cin &gt;&gt; refVal;
}

int rFib(int n)
{
     static std::vector&lt;int&gt; fib;
     static bool baseReached = false;
     fib.push_back(n);

     if (baseReached)
     {
             dispSeq(fib);
     }

     if (n &lt;= 1)
     {
        baseReached = true;
        return n;
     }
     else
     {
        return rFib(n-2) + rFib(n-1);
     }
 }

void dispSeq(std::vector&lt;int&gt; &amp;v)
{
    for (size_t i = 0; i &lt; v.size(); i++)
    {
        std::cout &lt;&lt; v[i] &lt;&lt; " ";
    }
    std::cout &lt;&lt; std::endl;
 }
Its normal to put parameter names even in the declarations:

void getUserNum(int &amp;);


We use this to help us identify what the function is doing.

In C++ the '*' and the '&amp;' are part of the type information. So it is usual to push these left towards the type rather than the name. Note this is basically the opposite of C conventions. But C++ is much more rigorous on types and safety than C.

void dispSeq(std::vector&lt;int&gt; &amp;vRef);

// Normally in C++ code I would expect this:
void dispSeq(std::vector&lt;int&gt;&amp; vRef);


Be careful with your use of out parameters.

void getUserNum(int &amp;refVal)


It seems more natural to return a value from a function then get sombody inside to set an external value via a reference (not unheard of and it will depend a lot on the context). But in this situation I would return a value. It will then make using the code eaiser.

 int userNum   = getUserNum();


Error Checking (especially input from a human) needs to be more rigorous.

void getUserNum(int &amp;refVal)
{
    std::cout &lt;&lt; "Enter a positive integer:\n";
    std::cin &gt;&gt; refVal;
}


If a user enters a non positive value things will go bad. If the user inputs a string the value of refVal I believe is left unaltered (which leaves your code with an uninitialized variable).

int getUserNum()
{
    int result;

    // user input is done by the line.
    // so read a line at a time and validate it.
    std::string  line;
    std::getline(std::cin, line);

    std::stringstream  linestream(line);

    int result;
    if (linestream &gt;&gt; result)
    {
         // The read worked.
         // Lets check the user did not type ofther crap on the line.
         //
         char x;
         if (!(linestream &gt;&gt; x))
         {
               // Reading more data worked. This means the input was good.
               // As the user typed a number followed by some other stuff
               // like  56.4   (the .4 is illegal)
               //       5Plop  (the Plop is illegal)
               //
               // The the above would have successfully read a value into
               // `x` this with the ! it would have failded and this
               // this condition would not have been entered.

               // We only return if:
               //    1. We read an integer. 
               //    2. There is no other data on the line except white space.
               return result;
         }
    }
    // invalid input
    std::cout &lt;&lt; "Stupid user input aborting\n";
    exit(1); // Reading failed.
             // Leave as an exercise on how to repeat the question.
             // You can also compress that very verbose if statement into a single
             // line without it looking too bad.
}

// Single line if
if ((linestream &gt;&gt; result) &amp;&amp; !(linestream &gt;&gt; x))
{   return result;
}


In Fib() you should probably not use recursion. Prefer a while loop. Loop from 0 upto the point you want to reach. This makes using a vector easy. You can also start from where you left off last time rather than 0.

int fib(int n)
{
     static std::vector&lt;int&gt;   values = {1,1};
     if (n &lt; values.size()-1) }return values[n];

     int start = values.size();
     for(int loop = start; loop &lt; n; ++loop)
     {
          values[loop] = values[loop-2] + values[loop-1];
     }
     return values[n];
}