Lets see:
Enter integers (-1 to end):
-3
-4
-1
Maximum: 0 |
The program does clearly fail here. The correct answer would be -3.
The initial value of max could be anything, because it is not
initialized with any known value. On that test run it happened to be 0. It could have been 132476579.
You want the max start with something that cannot be bigger than the input.
See
http://www.cplusplus.com/reference/limits/numeric_limits/
int max = std::numeric_limits<int>::min();
Lets try a different input:
Enter integers (-1 to end):
-1
Maximum: 0 |
An another failure. Let me update the code with proper initialization:
Enter integers (-1 to end):
-1
Maximum: -2147483648 |
Okay, the program has two issues:
1. It relies has undefined behaviour (uninitialized max)
2. The logic of "no integers entered"
No. The code does not "work". It might look like giving expected output for some input, during some phases of the moon, but that is far from "working".