 Wrong challenge answers | SoloLearn: Learn to code for FREE!

+2

# Wrong challenge answers

There was this question, several times in the challenges: int x = 1; for(int i=3; i<5; i++){ x += i; } cout << x; According to the computer, 8 is not the right answer. Is this a mistake?

7 Answers

New Answer

+9

@Kunene: You are almost right, but only, if i<=5. In the above code though we have i<5. Hence, it will run in 2 loops with x=4 and subsequently x=8.

+8

If you compile the code above the result is '8', according to ideone. Check here: http://ideone.com/iMhH6m

+3

So, basically, most people answering here say the example code outputs 8, including myself. I just copy pasted your example code on the playground and it says the output is 8, as well. Did you misremember the phrasing? Or is the answer wrong? Take a screenshot of the question if you see it again and send to Sololearn if you are right.

+2

Yes, this is a mistake. 8 is the right answer.

+1

yes ....the answer should be 8.......and nothing else....

-3

no it is not, first iteration i is 3, second iteration i is 4, third iteration i is 5 so the loop code is not executed

-10

This is no mistake, the answer is 13, this program loops three times, therefore x = 1 when loop is entered, x= 4 after first loop, x= 8 after second loop, x = 13 after third loop, making the final answer x=13