Ask your own question, for FREE!
Computer Science 19 Online
sleepyjess:

lalalalala

sleepyjess:

First one: 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%. This is what I have so far, but it's saying the output is incorrect int x = FIRST_YEAR; while(x <= LAST_YEAR) { oil *= 1.2; cout << x << ": " << oil << endl; x++; }

sleepyjess:

@bananas

bananas:

do you have oil defined? What happens when you run your own code with 2009 and 2014?

sleepyjess:

1 attachment
sleepyjess:

In case that helps at all

bananas:

it does, move oil after print

bananas:

i mean move oil*=1.2 after cout

sleepyjess:

that worked... why did it need to be after the cout statement?

bananas:

because you had already increased the percentage and then printed it. It wants you to assume you start with 300, print then increase.

sleepyjess:

ohh, okay, that makes sense

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!