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

@nuts @ultrilliam

sleepyjess:

I already finished the question, just don't understand why the solution is what it is

1 attachment
sleepyjess:

I guess my main question would be why isn't it k<=?

Ultrilliam:

<= is less then or equal too, while < is less then

sleepyjess:

but it wants 97, so while k is less than 97, it would only do 96?

Ultrilliam:

Correct, while it would go to 97 with less then or equal to

sleepyjess:

couple more loops if you don't mind?

Ultrilliam:

I just read the question... wait... what?

Ultrilliam:

it would only go to 96, yet it counts that as right ok then

sleepyjess:

yep, and it counts <= as wrong

sleepyjess:

1 attachment
Ultrilliam:

hold that thought, I'm going to go put some cookies in the oven

1 attachment
sleepyjess:

I know after each year, there'll be something like `oil*1.2`, but I have no idea how to do what they want for the first year to last year thing

sleepyjess:

`oil = oil*1.2` `cout << something to do with the years << ": " << oil;` something like that maybe? or am I totally off....

Ultrilliam:

@nuts you wanna do it, I somehow got stuck doing a physics assignmnet

sleepyjess:

int x; while(FIRST_YEAR <= x || x <= LAST_YEAR) { oil *= oil * 1.2; cout << x << ": " << oil; x++; } did this, and it's almost correct Remarks: ⇒ When executed, your code tried to create an excessively large file. A common cause for this is an infinite loop. Carefully check the condition and the loop body of any loop that does output. More Hints: ⇒ You almost certainly should be using: =

nuts:

i would but i needa sleep :(

sleepyjess:

;-;

Ultrilliam:

you used a or statement ```javascript while(FIRST_YEAR <= x || x <= LAST_YEAR) {} ``` while x is greater then x or less then last year it will always evaluate to true, you should be using and (&&)

Ultrilliam:

@sleepyjess

sleepyjess:

oooohhhhh, got the 2 confused...

sleepyjess:

1 attachment
Ultrilliam:

also ``` oil *= oil * 1.2; ``` here is your second issue you're multiplying it twice you should either be doing ``` oil *= 1.2; ``` or ``` oil = oil * 1.2; ```

sleepyjess:

okay, changed that to oil *= 1.2, but still getting the same error message

Ultrilliam:

try ``` oil = oil * 1.2; ``` then?

sleepyjess:

no issue with the oil statement, it got mad when I tried that way lol

Ultrilliam:

hm, that's the only issue I see *scratching head*

sleepyjess:

int x; while(FIRST_YEAR <= x && x <= LAST_YEAR) { oil *= 1.2; cout << x << ": " << oil << endl; x++; } that's what I have currently

sleepyjess:

1 attachment
sleepyjess:

something to do with the colon maybe?

Ultrilliam:

wait, is it saying oil isn't even output? :thinking_face:

sleepyjess:

yep, saying nothing is being outputed

sleepyjess:

I'll just email prof in the morning...

Ultrilliam:

give me a sec

Ultrilliam:

Yea, let's postpone those until tomorrow, *continues to figure this out* this would be so much easier of my visual studio installation was working

Ultrilliam:

*re-reads instructions*

Ultrilliam:

ooooooh

Ultrilliam:

>x isn't defined

Ultrilliam:

(as a number)

sleepyjess:

huh?

Ultrilliam:

Figured it out

sleepyjess:

didn't I define it with the `FIRST_YEAR <= x && x <= LAST_YEAR`?

Ultrilliam:

Why did you define x? ``` int x; while(FIRST_YEAR <= LAST_YEAR) { oil *= 1.2; cout << ": " << oil << endl; FIRST_YEAR++; } ```

Ultrilliam:

if my intuition is right

sleepyjess:

because it wants the year on each line

Ultrilliam:

Yes, but first year is already defined

Ultrilliam:

ok

Ultrilliam:

wait, it says nothing about that

1 attachment
Ultrilliam:

it just says that each year it increases by 20%

Ultrilliam:

(hence the 1.2)

sleepyjess:

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,

Ultrilliam:

ah "after the year" in that case

Ultrilliam:

``` int x; while(FIRST_YEAR <= LAST_YEAR) { oil *= 1.2; cout << FIRST_YEAR << ": " << oil << endl; FIRST_YEAR++; } ```

Ultrilliam:

wait, why am I still defining x in that

Ultrilliam:

```cpp while(FIRST_YEAR <= LAST_YEAR) { oil *= 1.2; cout << FIRST_YEAR << ": " << oil << endl; FIRST_YEAR++; } ```

Ultrilliam:

Does that wokr?

Ultrilliam:

work?*

sleepyjess:

1 attachment
Ultrilliam:

got it, then I got this

Ultrilliam:

```cpp int x = FIRST_YEAR ; while(x <= LAST_YEAR) { oil *= 1.2; cout << x << ": " << oil << endl; x++; } ```

Ultrilliam:

the stdout will still be wrong tho, hm, it's at least outputting something now though

sleepyjess:

yep, still says stdout is wrong

sleepyjess:

>_<

Ultrilliam:

hmmm

sleepyjess:

@nuts any idea why this is still wrong?

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!