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
![]()



LinkBack URL
About LinkBacks



