In the online compiler, the code ( http://cpp.sh/4gnfb ) as you type:
4 1 2 3 4 displays YES , and in Visual Studio displays NO .
In short, the code should output YES , if there is 0 among the N numbers. I know that it could be written more simply and concisely, the problem of different output is important to me. What could be the problem? In the online compiler, I poked different versions of c ++, the result is the same.
Code below:
int main() { int N, i = 0, a; cin >> N; bool NovyiGod2018; while (i < N) { cin >> a; if (a == 0) { NovyiGod2018 = 1; } else if (NovyiGod2018 != 1) { NovyiGod2018 = 0; } ++i; } if (NovyiGod2018 == 1) { cout << "YES"; } else { cout << "NO"; } }
warning C4701: potentially uninitialized local variable 'NovyiGod2018' used- VTT