Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Ternary Conditional Operator Problem

$
0
0
Alright, so i wanted to make a game of tic tac toe . And i wanted to use ternary conditional operators to ease up things .. the problem is it made my life a hell hole. As much as i think it trough it doesn't add up. So my problem is it always gives the result of array[0][2] . Here is the source so it can make any sense.

class Board{
public:
	Board( )
	{	
		m_GameBoard[0][0] = 'o';
		m_GameBoard[0][1] = 'o';
		m_GameBoard[0][2] = 'x';
	}

	int CheckGameStatus( )
	{
		// 0  ---- o Wins
		// 1  ---- x Wins
		// -1 ---- continues


		//Check first row
		int Status = (m_GameBoard[0][0] && m_GameBoard[0][1] && m_GameBoard[0][2] == 'x') ?  1 : (( m_GameBoard[0][0] && m_GameBoard[0][1] && m_GameBoard[0][2] == 'o' ) ? 0 : -1);

		return Status;

	}

private:

	

private:
	
	char m_GameBoard[3][3];
	
};



Any ways on top of your head to fix this w/o switching from ternary conditional operators ?
PS: sorry for my bad way of explaing things
Thanks

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>