Debugging help for ZCO14001 [C++]

I submitted my answer and only one test case(#5) is giving wrong answer
Can someone tell me what I did wrong ?
Solution
Question

Any other critique on formatting efficiency will be appreciated

One thing that immediately sticks out is that you are not initialising the value of comm before you check its value.

But that’s the first thing I did in the for loop ?

https://www.codechef.com/viewsolution/26143703

Here is my code
Not able to find any difference between your code and my code

The check is performed before you enter the body of the loop.

So probably a freak case ?

New Solution

You mean like this ? Still doesn’t work

No - I mean you should initialise the value of comm before you check it XD

I really don’t understand what else you mean

Can you please type it out :slight_smile:

1 Like

Give comm a value before checking its value in any condition! Read about difference between declaration and initialisation.

2 Likes

Like this - see the change on line 21:

https://www.codechef.com/viewsolution/28412823

1 Like

Thank you so much , your help is very much appreciated but why was this causing error after all eventually a value was gonna go into comm

1 Like

if you don’t give it a value to begin with, then the initial value of comm is undefined i.e. it’s allowed to have any value at all, including 0. If it happens to have the initial value 0, then the for loop simply never gets executed at all.

1 Like