Hello, we are supposed to write a program to find the population of crud after a certain period of time using 3 different types of loops. I will post the question:
The following program is to be written with a loop. You are to write this program three times and each time with a different loop control structure (for loop, while and do-while).
The Fibonacci numbers Fn are define as follows. F0 is 1, F1 is 1, and Fi = Fi-1 + Fi-2 for i = 0, 1, 2, 3, ... In other words, each number is the sum of the previous two integer numbers for F2. 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 two time periods to mature to reproducing age, and then the organism reproduces once every time period (thus the reason for two 1's before you start adding). The formula applies most straightforwardly to a sexual 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 3 days. Hence, if a green crud population starts out as 3 pounds of crud, then in 5 days there is still 3 pounds of crud; at the end of the second 5 days there is still 3 pounds of crud; (ie the first two Fib numbers are 3) then in 5 more days we have 6 pounds (the sum of the previous two 5 day periods). Write a program that takes both the initial size of green crud population (in pounds) and a number of days as input, and output the number of pounds of green crud after that many days of growth. Assume that the population size is the same for 5 days and then increases every fifth day.
Input to the crud program: start with 3 pounds of green crude and display the how much crude we have after 190 days. Run each of the three versions of the program with 190 days. You can NOT use arrays for this program.
Now, what happens when you run the program for 250 days when you use the simple data type ‘int’? (Not long int or double data types please.)
I have no idea how to implement that into a loop for the formula. I wrote just the bare bones for now, but if I could see how to start it, that would really help me get going on this. Thanks everyone. We can't use arrays and we haven't learned vectors and all that. I could do functions though.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int days,i;
int crud, total;
cout<<"How many days are we testing for?: "<<endl;
cin>>days;
cout<<"How many pounds of crud to start?: "<<endl;
cin>>crud;
for(i=0;i<days;i++)
{
//have no idea what to put here
}
cout<<total;
//table
cout<<endl;
cout<<"-----------------------------------------------------------------"<<endl;
cout<<"Initial Amount "<<setw(16)<<"Number of Days "<<setw(20)<<"Total Crud After"<<endl;
cout<<"-----------------------------------------------------------------"<<endl;
cout<<setw(5)<<crud<<"lbs"<<setw(18)<<days<<endl;
return 0;
}
|