. Modify your previous program so that the user can enter the total number acres
ID: 3808901 • Letter: #
Question
. Modify your previous program so that the user can enter the total number acres and the number of uncut acres. The reforestation rate will remain fixed at 0.02. Your program will display the initial parameters, e.g, total number of acres, number of uncut acres, and the reforestation rate. The program will compute and display the number of years it will take until the number of acres cut will be completely renewed. [Note: In one year the number of reforested acres may be less than the total number of acres, while the next year the number of reforested acres may actually exceed the original total number of acres. That means, it is unlikely that at the end of the last year you will find that the forest has reached the exact size at which it started. Beware of “off-by-one” type errors, i.e., a program incorrectly reports a number that, in this case, reports a year that is one year too early or one year too late.]
The code needs to be in C
E int main (int argc, cha char arg t argv int years; float rate Tb, Tbr, Ta printf "Enter the number of acres before the cut scanf ("%f", &Tb;); printf ("Enter the number of acres after the cut: scanf ("%f", &Ta;); years 03 rate 0.02 while year Tb Ta Ta rate years; printf ("After %d years %f acres have regrown to f acres ', years, Ta, Tb); always last 3 lines of main printf Inpress enter to quit:"); getchar return 0;Explanation / Answer
Code:-
#include <stdio.h>
int main(void) {
int years;
float rate,Tb,Tbr,Ta;
printf("Enter the number of acres before the cut:");
scanf("%f",&Tb);
printf("Enter the number of acress after the cut:");
scanf("%f",&Ta);
years=0;
rate=0.02;
while(Tb>=Ta){
years++;
Ta=Ta+Ta*rate*years;
printf("After %d years %f acres have regrown to %f acres ",years,Ta,Tb);
}
printf(" press enter to quit:");
getchar();
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.