Relational Operators
Dec 30, 2014 at 7:17am UTC
I know the following code that you will see is probably the ugliest thing that you have ever seen. I apologize for that. Anyhow, I am currently trying to meet the condition down below with the "if" statement. However, no matter what combinations I try, I cannot seem to make it print "Winner." Any suggestions?
P.S., I am trying to write a Tic Tac Toe program.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
#include <iostream>
using namespace std;
int main()
{
int j = 0;
int k = 1;
int board[9];
for (int i = 1; i < 10; i++)
{
if (i == 1 || i == 3 || i == 5 || i == 7 || i == 9)
{
cin >> board[j];
j = j + 2;
}
if (i == 2 || i == 4 || i == 6 || i == 8)
{
cin >> board[k];
k = k + 2;
}
}
if (((board[0] || board[2] || board[4] || board[6] || board [8]) == 1) &&
((board[0] || board[2] || board[4] || board[6] || board [8]) == 2) &&
((board[0] || board[2] || board[4] || board[6] || board [8]) == 3))
cout << "winner" ;
return 0;
}
Dec 30, 2014 at 7:53am UTC
1 2 3 4
if ( ( board[0] || board[1] || board[2] ) == 1 ) // wrong
if ( board[0] == 1 || board[1] ==1 || board[2] == 1 ) // correct
Dec 31, 2014 at 7:05am UTC
Gosh. Thank you so much.
Best, Jae Kim
Topic archived. No new replies allowed.