I've been playing around with the code below in order to try to accurately predict its output, but what I'm receiving is the total opposite of what I'd expect so I must be interpreting it incorrectly.
#include <iostream>
#include <string>
usingnamespace std;
int player = 1;
int main()
{
do
{
cout << player << endl;
player++;
player = (player % 2) ? 7 : 4;
cin.get();
}
while
(
player < 9
);
return 0;
};
The output I expect is:
1
7
4
7
4
7
...
Instead I receive:
1
4
7
4
7
4
...
In line 13 I'm using the ternary operator and I'm using the value "7" for when the condition is true and "4" for when it is false. I find it weird that I receive the output in this order because it is the equivalent of if I said:
1 2 3 4
cout << player << endl;
player++;
player = (player % 2 == 1) ? 7 : 4;
cin.get();
Notice: (player % 2 == 1)
Does that mean that simply declaring "player %2" is the equivalent of "player %2 == 1" as opposed to "player %2 == 0"?