Assume that two int constants,FIRST_YEAR and LAST_YEAR have already been declared and initialized with year values (like 2009, 2014), along with a double variable oil that has been initialized with the number of barrels of oil consumed in Canada in the year given by FIRST_YEAR. Write some code that uses a while statement to print on a line by itself, each of the years from FIRST_YEAR to LAST_YEAR inclusive. On each line, after the year, separated by a colon and a space, print the new value amount of oil, taking into account that each year the oil consumed increases by 20%.
.
.
Click on the title for the solution
.
.
int i = FIRST_YEAR;
while(i <= LAST_YEAR)
{
cout<< i << ": " << oil<< endl;
oil = oil + (oil * 0.2);
i++;
}
.
Click on the title for the solution
.
.
This is the answer:
:
int i = FIRST_YEAR;
while(i <= LAST_YEAR)
{
cout<< i << ": " << oil<< endl;
oil = oil + (oil * 0.2);
i++;
}
Comments
Post a Comment