Hi brand new,

Okay so I have an exercise I'm doing to better help understand C++ programming. This isn't a project or homework assignment. I'm doing this for practice and to better my skills as a programmer. I have the logic down, now I just need to add to the population every 5 days.

Here's my exercise:

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

Here's my code:

``````#include <iostream>

using namespace std;

int main(){
int input(0), current(0), pervious(1), total(1);
cout << "Please input the number of Fibonacci sequences you'd like to be calculated: ";
cin >> input;

for(int i = 0; i <= input; i++){
cout << total << endl;
total = current + pervious;
current = pervious;
pervious = total;
}
return 0;
}``````

Hi

It looks like you have missed a few points. First of all, look at the facts.
There are two inputs: the starting amount and the timespan. Ask those two numbers from the user.
Also, every five days there is a growing, not every day. Add that to your function.
Finally, output only one number, the final amount of green crud.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.