Brian Foulke

Problem:

We are to write a program that will take in the initial size of the crud population and how many days that it will be growing for. We are to start the green crud population at 10 pounds, and that every 5 days it will grow by the Fibonacci sequence. After 5 days it will be 10 pounds, 10 days 20 pounds, 15 days 30 pounds, and so on. If the user entered 13 days it would only grow for the first 10, then the next three would have no effect on the population. The Fibonacci sequence, which goes 1, 1, 2, 3, 5, 8, and so on, also could be shown as C = A + B, then D = B + C, E = C + D, and so on, will be used to show the growth. Basically it adds the previous two numbers to get the new one. We should have a control structure that allows the user to repeat this process as many times as they want. In the for loop we will have I starting at 0 and climbing. For I =0 we have F2 = F1 + F2 ( F2 = 10 + 10), then for I = 1 we have F3 = F2 + F1 (10 + 20 = 30).

Solution:

We can start out by creating the variable for green crud and also A and B, which will temporarily hold the value of lbs of crud. Then we can create a variable for days, that the user will be inputting. We need to subtrat 5 from the number of days because the crud does not grow in the first 5 days. We can then create a for loop, for(I = 0; I <= tempDays; i++) to start with. Before the loop we need to set a variable, tempDays, and divide this by 5 to see how many times this loop will run. Inside the loop we will be setting up the fibonacci sequence. First we can set F = A + B which will hold the same value as lbs of crud. Now we must install another loop before this, an if-else loop, where if I % 2 = 0, then F = a, else F = b. This should set every other answer to A and B. The first time thru the loop a and b would equal 10, which sets F to 20, and since (I%1) != 0, then B is now 20 as well. The next time thru the loop ( I = 2) it will be F = 10 + 20, setting F to 30, and also since i%2 = 0, it now sets A = 30 so the next time thru the loop we will get 50. After the loop is done running, we will now have a final value for F, so we know the lbs of green crud total. After the loop we can use the mod operator with days, to tell the user how many days until the population will grow again, by using tempDays = (days%5), then tempDays = 5 – tempDays, which will give us how many days until it will grow again. At the end of the program it will output the new lbs of crud, as well as how many days until it will grow again. Then it will ask if you would like ot run the program again.

Algorithm:

Get values for lbsOfCrud, and days.

Set the value ofs lbsOfCrud = A and B

tempDays = days/5.

Set up the loop for(I = 0; I <= tempDays; i++)

{ F = A + B

While (i%2 = 0)

A = F

Else B = F

}

Display the output of F, which will be put into lbsOfCrud.

Then we can use tempdays = (days%5)

tempDays = 5 – tempDays to give the user how many days until the crud will grow again.

Then we ask if they would like to run the program again. And either we run it again or we exit the program.