Exponentiating Rabbits with Recursion and While Loop
<h2>I asked a question on here a few days ago about this Rabbits program, and I managed to ALMOST finish it. The problem is that when I input 0, it crashes and doesn't run. Can somebody help me out, here is my task:</h2>

<p>A pair of newly born rabbits (one male, one female) is put in a field. Rabbits are able to mate at the age of one month so that at the end of the second month each pair produces two new pairs of rabbits and then dies.
Note: In month 0, there are 0 pairs of rabbits. In month 1, there is 1 pair of rabbits.</p>

<ol>
<li>Write a program – using a while loop – that takes the number of months from the user and prints the number of pairs of rabbits at the end of that month.</li>
<li>In the same cpp file, write a recursive function rabbits() that takes the number of months as input and returns the number of pairs of rabbits at the end of that month.</li>
<li>In the main program, call the function rabbits() with the number that the user entered. Output both calculations (i.e. the one you obtained with the loop and the one that the recursive function returns) and see if they are equal.</li>
</ol>

<hr>

<pre><code>#include &lt;iostream&gt;
using namespace std;

int rabbits (int);

int main ()

{
int month_function, month_while, result_rec, result_while, counter = 0, rab_now, rab_lastmonth = 0, rab_twomonthsago = 1;

cout &lt;&lt; "Please enter the month. \n\n";
cin &gt;&gt; month_function;
month_while = month_function;
cout &lt;&lt; "\n";

if (month_function % 2 == 0) // if month entered is even, the recursive function will use month - 1 because the total number of rabbits doubles every other month
{
    month_function--;
}

result_rec = rabbits (month_function);

while (counter &lt; month_while)
{
    if (counter % 2 == 0)
    {
    rab_now = rab_lastmonth + rab_twomonthsago;
    rab_lastmonth = rab_now;
    rab_twomonthsago = rab_now;
    }
    counter++;
    result_while = rab_lastmonth;
}

cout &lt;&lt; "According to the recursive function, there are " &lt;&lt; result_rec &lt;&lt; " pairs of rabbits at the end of month " &lt;&lt; month_while &lt;&lt; "\n\n";

cout &lt;&lt; "According to the while loop, there are " &lt;&lt; result_while &lt;&lt; " pairs of rabbits at the end of month " &lt;&lt; month_while &lt;&lt; endl;

if (result_rec = result_while)
{
    cout &lt;&lt; "\n";
    cout &lt;&lt; "They are equal!" &lt;&lt; endl;
}
else
{
    cout &lt;&lt; "They are not equal!" &lt;&lt; endl;
}

return 0;
}

int rabbits (int month_function)

{
    if (month_function == 0)
    {
        return 0;
    }
    else if (month_function == 1)
    {
        return 1;
    }
    else
    {
       return (rabbits (month_function - 2) + rabbits (month_function - 2));
    }
}
</code></pre>
