He said that he has fixed that. If so, then there is version control issue, i.e. he still has "bad" versions around to copy-paste from.
Line 12 probably should tell the user that only positive natural numbers (N) are expected, rather than the whole mathematical set of integers (Z). The current version is like going to exam and having to write the answers
before the questions are revealed.
On should include line 13 in line 14.
if ( cin >> a >> b >> c && 0 < a && 0 < b && ...
The reason is that the user can type silly things and then a, b, and/or c might have undefined value. Obviously, the ELSE branch has to check whether the IF failed due to input error or due to non-positive input.
"Unroll loop", for fun:
1 2 3 4 5 6
|
winner = arr[0];
size_t i = 1;
while ( i < n ) {
if ( winner < arr[i] ) winner = arr[i];
++i;
}
|
Set n = 3. We can now replace the while with repeating instructions:
1 2 3 4 5 6
|
winner = arr[0];
size_t i = 1;
if ( winner < arr[i] ) winner = arr[i];
++i;
if ( winner < arr[i] ) winner = arr[i];
++i;
|
winner == arr[0]
i == 1 < n
arr[i] == arr[1]
i == 2 < n
arr[i] == arr[2]
i == 3 == n |
And remove the i altogether:
1 2 3
|
winner = arr[0];
if ( winner < arr[1] ) winner = arr[1];
if ( winner < arr[2] ) winner = arr[2];
|
Replacing arr[0], arr[1], and arr[2] with a, b, and c is now trivial.