//Solution
#include <iostream>
usingnamespace std;
int main() {
// Input and loop defined, only adds if input is correct.
for (shortint i = 8, input; i <= 23; i += (i == input)) {
cout << "Enter the number " << i << ": ";
cin >> input;
}
return 0;
}
Since this was the first time I've seen this, can someone explain to me why the for loop increment accepts a condition?
Also, I thought that += was the addition assignment operator? In this case I can see that i increments only when i == input, but if:
a = a+b
a += b
are both the same thing, how can i += (i == input) be the equivalent of doing ++i in this case?