Help with Rabbit population program

Hello all. I'm new to C++ and I'm struggling with a homework assignment. It reads as follows:

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.



My first thought was Fabornacci, which is easy enough to implement using recursion. But the rabbits die every month, making Fabornacci inapplicable. Further, we haven't done exponential functions in class, so we are not allowed to do that. Thoughts?

the sequence should be: Month 0: 0 rabbits. Month 1: 1 pair of rabbits. Month 2: 2 pairs of rabbits. Month 3: 2 pairs of rabbits. Month 4: 4 pairs of rabbits. Month 5: 5 pairs of rabbits. And so forth.
What is the sequence in total rabbit not pairs. I'm confused can you just give the numbers please.
{2,4,6,8,10}

Where the numbers are the total rabbits not the pairs.
Forget what I say.
@sunzzip102

the sequence should be: Month 0: 0 rabbits. Month 1: 1 pair of rabbits. Month 2: 2 pairs of rabbits. Month 3: 2 pairs of rabbits. Month 4: 4 pairs of rabbits. Month 5: 5 pairs of rabbits. And so forth.


Actually, that's wrong. Each pair will produce 2 pairs, so, month 0, 0 pairs, month 1, 2 pairs, month 3, 8 pairs, month 4, 32 pairs, and so on... Remember, each pair, will will have 4 rabbits, or 2 pair.

each pair produces two new pairs of rabbits
You might be able to use two recursive rules for a geometric series.One for the growth subtracted from one for the decay.
Topic archived. No new replies allowed.