Still stuck on this one. I am not back in class yet. This is my personal research/review for the upcoming semester. I am not where I'd like to be with my review, but I really want to solve this one; but I can't seem to get started. Can someone please help me "LOGIC" this thing out??? It seems easy enough, but I don't see it:
The Fibonacci numbers Fn are defined as follows: F0=1, F1=1, and Fi+2 = Fi + Fi+1 for i=0,1,2... . In other words, each number if the sum of the previous two numbers. The first few Fibonacci numbers are 1,1,2,3,5,8. One place that these numbers occur is as certain population growth rates. If a population has no deaths, then the series shows the size of the population after each time period. It takes an organism two time periods to mature to reproducing age, and then the organism reproduces once every time period. The formula applies most straightforwardly to asexual reproduction at a rate of one offspring per time period.
Assume that the green crud population grows at this rate and has a time period of 5 days. Hence, if a green crud population starts out as 10 pounds of crud, then in 5 days there is still 10 pounds of crud; in 10 days there is 20 pounds of crud; in 15 days 30 pounds, in 20 days 50 pounds, and so forth. Write a program that takes both the initial size of a green crud population in pounds and a number of days as input and outputs the number of pounds of green crud after that many days. Assume that the population size is the same for four days and then increases every fifth day.
// **************************************************************************
//
// GreenCrud.cpp
//
// Determines the size of the green crud population on any given day.
// Assumes that green crud reproduces every 5 days starting when
// it is 10 days old,giving a growth rate following the Fibonacci sequence.
// So if there is a new crud population of 10 pounds on day 0, the
// crud population at increments of 5 days beginning with day 0 are as follows:
// 10, 10, 20, 30, 50, 80, 130, ...
// That is, on day 0 there are 10 pounds; on day 5 there are still 10 pounds;
// on day 10 there are 20 pounds; on day 15 there are 30 pounds; and so on.
// **************************************************************************
The whole focus of this chapter was to implement loops. I just don't see how to utilize the loop with a conditional which will only increment a given input every 5. Previously, Salem gave me this, and I don't know what the mod does here (Thanks for any and all help!!):
8 Days Ago | Add to Salem's Reputation | Flag Bad Post
So what's the difference between these two?
(Toggle Plain Text)
for ( day = 0 ; day < 100 ; day++ ) {
if ( day % 5 == 0 ) {
theNextGeneration();
}
}for ( day = 0 ; day < 100 ; day++ ) {
if ( day % 5 == 0 ) {
theNextGeneration();
}
}
(Toggle Plain Text)
for ( day = 0 ; day < 100 ; day += 5 ) {
theNextGeneration();
}for ( day = 0 ; day < 100 ; day += 5 ) {
theNextGeneration();
}
The rest is nothing more than a Fibonacci series.
A REMINDER: THIS IS NOT AN ASSIGNMENT, BUT I'M REVIEWING OVER BREAK