[Solved] Simple IF statement not working correctly


Your problem is simple and mayankTUM has already answered it, but you can do it with the power of the STL.
I wrote a sample to show you :

#include <iostream>
#include <list>
#include <algorithm>
#include <string>

#define ROWS 1
#define COLS 4

using namespace std;

bool checkWinner(string board[ROWS][COLS])
{
    list<string> l;
    l.push_back("WSHR");
    l.push_back("WTHR");
    l.push_back("WTFR");
    l.push_back("WSHC");
    l.push_back("WTFC");
    l.push_back("WSFR");
    l.push_back("WTHC");
    l.push_back("WTFC");

    bool hasWon = true;
    for(int col = 0; col < COLS && hasWon; ++col)
    for(int row = 0; row < ROWS && hasWon; ++row)
    {
        hasWon &= find(l.begin(), l.end(), board[row][col]) != l.end();
    }

    if(hasWon)
    {
        cout << "Winner!!!!!" << endl;
        return true;

    }
    return false;
}

int main()
{
    string board[ROWS][COLS] = {"WSHR", "WTHR", "WTFR", "WSHC"};
    string board2[ROWS][COLS] = {"WSHR", "WTHR", "WZFR", "WSHC"};

    cout << "board has to be true : " << boolalpha << checkWinner(board) << endl;
    cout << "board2 has to be false : " << boolalpha << checkWinner(board2) << endl;

    return 0;
}

And the result is :
Winner!!!!!
board has to be true : true
board2 has to be false : false

The code is pretty obvious, so I think I don’t need to explain it, but feel free to comment if you need more precisions.

solved Simple IF statement not working correctly