The advantage of this approach is that program only needs one prompt and one read operation.
#include <iostream> using namespace std; int main() { int score; int max = 0; while (true) { cout << "Enter a score (-1 to end): "; cin >> score; if (score == -1) break; if (score > max) max = score; } cout << "The maximum score is " << max << endl; return 0; }