Need Suggestions on how to start with a For loop
A problem in timber management is to determine how much of an area to leave uncut so that the harvested area is reforested in a certain period of time. It is assumed that reforestation takes place at a known rate per year, depending on climate and soil conditions. The reforestation rate expresses this growth as a function of the amount of timber standing. For example, if 100 acres are left standing and the reforestation rate is .05, then at the end of the first year, there are 100+.05*100 or 105 acres forested. At the end of the second year, the number of acres forested is
105+.05*105 or 110.25 acres.
Assume that the total area to be forested, the uncut area, and the reforestation rate are known. Write a program to determine the percentage of the total area that is forested after X years. The program should be user friendly with prompts and comments where needed. Remember the forest service depends upon you. Output should give the input data plus the number of acres forested and the percentage of the total that this represents.
Use the following input data to test the program:
************************************************** ******************************
Area Number Total Area Uncut Area Reforestation Rate
************************************************** ******************************
45 10,000 100 .05
83 1,000 50 .08
153 20,000 500 .10
192 14,000 3,000 .02
234 6,000 1,000 .01
years 20
i cant figure out how to start the for loop?
i know i need a LCV (loopcontrol variable) only one i could think of using is years like
for ( int years; years>0; years--)
but if this works what do i put after ? an if statement? to make it do the calculating? any suggestions would be greatly welcomed ;)
thanks in advance
416 18,000 1,500 .05
ko0 thanks..but we HAVE to use for loops grrr
ko0 whats the "*="? i havent came across that yet anywhere in class or any of the book so far?
when u used dAccum? that was for forested area right? an the loop the "i"? doesnt represent anything?
i think i get it kinda.........but all the example only have
for(int x=0;x<=100;x++)
cout << x
i have tried to place a C++ statement like area_forest=uncut_area+(rate*uncut_area)
but it just outputs a zero everytime.........
i think i am just completely LOST ::confused:
okie but what did u have dAccum stand for?
i havent seen it used in that form..........i guess the author of our book choose a different way or skipped it sorry........
i think i got it........just wondering why the dAccum?
oh yeah illpost part the "hopefully" working code in a few minz:rolleyes:
here is the part of the code i am having problems with.....
i cant seem to figure out whats wrong....i have narrowed it down to this loop
for (double i=1; i<years+1;++i)
{
area_forested = (uncut_area + (forest_rate * uncut_area)*i)
}
its supposed to input X number of years (years), the rate of reforestation(forest_rate), the area left uncut(uncut_area).
And then determine what the area forested will be after X years has passed.
when i enter i year it output 105 which is correct, but when i enter 2 yrs it output 110.00 and it should be 110.25, it seems to drop off all the decimals? I have set all my variables to double.
took out the set percission an then there was no decimal? I tested each section of my code an all is working fine except this for loop part? i get correct answers for years 1-9 without the decimal?
if it helps the desk check i am using is 20years,rate .05,total area 10,000 , and uncut area 100. i was told the answer should be something like 635.33?
......any ideas?.......i even confussed my prof. haha.....any suggestions will be greatlly welcomed
:confused: