This is not an error, but a warning from your compiler. It is telling you, that you are accessing an undefined value, because you did not initialize your variable.
A local variable that is not explicitely given a value is called 'uninitialized', because it assumes the value of 'whatever has been in the allocated block of memory', which far more often than not results in a garbarge value and definitely not what you want.
The first issue is in the loop. Depending on the garbage value in 'guess', it may decide to not run your loop at all (because 'guess' just might hold the value '5' by chance).
Another problem is your use of scanf. If the input does not match your requirements (i.e. not a number), guess
will remain unchanged. Please refer to the documentation on scanf for more details.
As a little anecdote I like to tell: I once had a bool
(C++, should only be true or false) variable that was uninitialized under certain circumstances.
Then, down the road, it was checked against if (!variable)
and, in the else condition it read else if (variable == true)
.
It did not enter either branch, because, as the debugger revealed, the value of my variable was neither true nor false. It was 42. That's the kind of danger uninitialized variables hold. You'll never know what you get.