0
what's wrong with this code?? #include <iostream> using namespace std; int main() { int n; int max=0; while (n!=0) { cin>>n; if(n>max) max=n; } cout <<max; return 0; }
5 Antworten
+ 2
It's because n doesn't hold a value when the while loop begins.
Set n to a non-zero value, such as 1 or -1,
or alternatively you could use a do/while loop rather than a while loop.
+ 1
if n isnt assigned any value then the compiler automatically assigns a garbage value
0
set n to non zero
0
n does not have any initial value assigned
0
thanks guys