I can code things okay, but I have real trouble coming up with algorithims to solve problems. For instance this problem:
'A scientist uses rabbits (yes, another rabbit problem) in her experiments. She starts out with one pair(male,female). At the end of each month, a pair of rabbits produces one pair of offspring(also male,female). The scientist has 500 cages to hold her rabbits. Each cage holds one pair of rabbits. Assuming no rabbits ever die, when will she run out of cages?'
The program should printout how the rabbits multiply and produce baby rabbits which then add to the total rabbit population. Then when the total pairs reach past 500 cages print out a message saying in what month that happens. For example:
Month Adults Babies Total
1 1 0 1
2 1 1 2
3 2 1 3
4 3 2 5
*snip*
12 144 89 233
Will run out of cages in month xx...
Really, I don't know where to begin other than making the first declarations:
const int CAGE = 500; // I dont know if i need this
int adultRabbits;
int babyRabbits;
int totalRabbits = adultRabbits + babyRabbits;
int month;
for
cout << "\n" << month << "\t" << adultRabbits << "\t" << babyRabbits << "\t" << pairs; // I know i need this to print the results right
I am thinking I need a loop, but not sure which one to use, For, While, Do, or If. And I definately don't know what math I may need to get the algorithim. Several different ones I suppose.
Any help is greatly appreciated.