0

I was given the assignment to show the population growth of rabbits per month (method), given the 3 variables, one variable for a newborn rabbit, one for a month old rabbit (which can give birth to a pair), and adults. I am uncertain what the syntax would be for calculating the age progression inside the wait method (per month)? Here was my assignment: - Suppose a newly-born pair of rabbits, one male, one female, are put in a field. Rabbits are able to mate at the age of one month so that at the end of its second month a female can produce another pair of rabbits. Suppose that our rabbits never die and that the female always produces one new pair (one male, one female) every month from the second month on. How many pairs will there be in ten months?

So here was my thought process. The waiting method (month method) in its own class is called 10 times from the main. When called, the newborn babies equal the month babies (they grow up to month babies) and the month babies equal the adults (they grow up to adults) at here, the newborn equals the adults.

public RabbitPopulation()
{ // Just a constructor to initialize instance variables
    Newborns = 1;
    MonthBabies = 0;
    Adults = 0;
    NewbornTemp = Newborns;
    MonthBabiesTemp = MonthBabies;
    AdultsTemp = Adults;
    Counter = 0;
}
public void MonthWait()
{
    MonthBabies = Newborns;
    MonthBabies -= MonthBabiesTemp;
    MonthBabiesTemp = MonthBabies;
    Adults += MonthBabies;
    Newborns = Adults;
}
// in the main program....\\
int i = 0;
RabbitPopulation Rabbits = new RabbitPopulation();
while (i < 10)
{
    i += 1;
    Rabbits.getPairs(i);
    Rabbits.MonthWait();
}

I should end up with a result of 89 rabbits after 10 months. However, I end up with 81 and a rabbit dies within the third-month :p (which is not intended, no rabbits die in this assignment). Please note I am a beginner at C#, don't batter me please

TITAN696
  • 1
  • 4
  • Good ole Fibonacci ... I believe it's 55 rabbits as well, not 89, the first 10 months would be `1, 1, 2, 3, 5, 8, 13, 21, 34, 55`... – Trevor Oct 14 '19 at 20:57
  • @Çöđěxěŕ ah yes that. Do you happen to know Fibonacci's syntax for C# or what I am doing wrong? – TITAN696 Oct 14 '19 at 21:05
  • Your assignment is based on the Fibonacci sequence... Please see [here](http://www.maths.surrey.ac.uk/hosted-sites/R.Knott/Fibonacci/fibnat.html#section1.1) Also if you [look](http://www.maths.surrey.ac.uk/hosted-sites/R.Knott/Fibonacci/fibseries.html) there at the chart, look under the number 10(months) it's 55... So you saying you ended up with 89 rabbits, it's 11 months, not 10 months. – Trevor Oct 14 '19 at 21:06
  • @Çöđěxěŕ ah yes I see it now, I have noticed the formula as 0 + 1 = 1 then 1 + 1 = 2 then 2 + 1 = 3. However, what would be the placeholders for these numbers as I have 3 temporary variables??? – TITAN696 Oct 14 '19 at 21:12
  • [Please](https://dotnetfiddle.net/tNyzOX) see that Fiddle. – Trevor Oct 14 '19 at 21:18
  • @Çöđěxěŕ apologies but I have not learned arrays yet, please don't judge. Do you have an alternative Fiddle that has basic variables rather than arrays? Thank you again. – TITAN696 Oct 14 '19 at 21:21
  • [Please](https://dotnetfiddle.net/IIhwf6) see that Fiddle. Basically it give's you to different totals of rabbits over a period of 10 months. – Trevor Oct 14 '19 at 21:28
  • @Çöđěxěŕ Thank you for providing more information! However, I do not understand the fib[0] or fib[1] arrays for I have not learned arrays yet, do you have any code without the use of [ ] or arrays? – TITAN696 Oct 14 '19 at 21:31
  • Not at this time, no sorry. Fibonacci forms a sequence, how would you go through it? – Trevor Oct 14 '19 at 21:41
  • @Çöđěxěŕ Good question, I will attempt to read your examples and the link you have provided. Thank you for assisting me! – TITAN696 Oct 14 '19 at 21:46
  • Welcome, good luck! – Trevor Oct 14 '19 at 21:52
  • Your code seems to work... see [this fiddle](https://dotnetfiddle.net/9S0v41) – haldo Oct 14 '19 at 21:58
  • This post is now solved! Thank you all for assisting me! – TITAN696 Oct 14 '19 at 22:44

0 Answers0