186k views
2 votes
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%.

User Vaso
by
8.9k points

1 Answer

2 votes

// While loop

while(FIRST_YEAR < LAST_YEAR)

{

cour<<"Year : " << First_YEAR << " Oil consumed is : " << oil <<"."<<endl;

FIRST_YEAR+=1;

// calculate the 20% increase

oil = oil + (oil *.20)

}

User Casenonsensitive
by
8.2k points