### Fibonacci Rabbits that die

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.

1. 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.

2. 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.

3. 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.

The description is fairly self explanatory. I already have the main program down, but I can't figure out how to implement the rabbits dying after reproducing.

**** This is my code so far, I don't know how to implement the rabbits dying, can anybody point me in the right direction?
------------------
 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950`` ``````#include using namespace std; int rabbits (int); int main () { int x, month, result, counter = 0, rab_now, rab_lastmonth = 1, rab_twomonthsago = 0; cout << "Please enter the month \n\n"; cin >> month; cout << "\n"; result = rabbits (month); while (counter <= month - 1) { rab_now = rab_lastmonth + rab_twomonthsago; x = rab_lastmonth; rab_lastmonth = rab_now; rab_twomonthsago = x; counter++; } cout << "At the end of month " << month << ", there will be " << rab_lastmonth << " pairs of rabbits" << endl; system("PAUSE"); return 0; } int rabbits (int month) { if (month == 0) { return 0; } else if (month == 1) { return 1; } else { return (rabbits (month + 1) + rabbits (month - 2)); } }``````
Topic archived. No new replies allowed.