Question: I need help with a Fibonacci program in C++ language. Here is the question: The Fibonacci numbers F are defended as follows. F0 is 1,

I need help with a Fibonacci program in C++ language.

Here is the question:

The Fibonacci numbers F are defended as follows. F0 is 1, F1 is 1, and FI+2 = Fi + Fi+1

I = 0, 1, 2, . In other words, each number is the sum of the previous two numbers. The first few Fibonacci numbers are 1, 1, 2, 3, 5, and 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 reproduces once every time period. The formula applies most straightforward to asexual production at a rate of one offspring pre 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 five days there will still be 10 pounds of crud; in 10 days there is 20 pounds of crud, in 15 days there will be 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 that outputs the number of pounds of green crud after that many days. Assume that the population size is the same for 4 days and then increases every fifth day. Your program should allow the user to repeat this calculation as often as desires.

Here is my code:

#include using namespace std;

int main( ) { // Varible declaration. char ans='y'; // Start whlie loop while (ans == 'Y' || ans == 'y') { // Initial crud size int init = 0; int newCrud; int next=0; // Number of days to simulate int no_days; int day; cout << "Please enter the initial number of pounds of green crud: "; cin >> newCrud; cout << "Enter the number of days the green crud has to reproduce: "; cin >> no_days; for (day = 10; day<=no_days; day++) { if (day % 10 == 0) { next = newCrud + init; } newCrud = init; init = next; } if (no_days<5) cout << " Crud reproduce only after 5 days minimum. Hence the current amoiunt is " << newCrud << " pounds."; else cout << "After " << no_days << " days, there should be " << init << " pounds of green crud scumming the pond." << endl; cout << " Would you to continue? (y or n) : "; cin >> ans; } return 0; }

I need help with the caculation, it just doesn't come out right.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!