I need help with a Fibonacci program in C++ language. Here is the question: The
ID: 3664254 • Letter: I
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, 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 <iostream>
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.
Explanation / Answer
#include int main() { const int time_period = 5 ; //declaring time period to be 5 days //looping program using do_while loop char ans ; // response for loop do { //asking user for weight of crud in pounds std::cout > initial_size ; std::cout num_of_days; int count = num_of_days / time_period; // making sure crud grows every five days. double f_1 = initial_size ; double f_2 = initial_size ; for( int i = 0 ; iRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.