title: 8 queens puzzle with user input c++
body: <p>I was studying the 8 queens puzzle and i wrote down my version of code that solved the problem with the first queen always put on row 0.</p>
  
  <pre><code>#include "stdafx.h"
  #include &lt;iostream&gt;
  using namespace std;
  
  
  const int NUMBER_OF_QUEENS = 8; // Constant: eight queens
  int queens[NUMBER_OF_QUEENS];
  // Check whether a queen can be placed at row i and column j
  bool isValid(int row, int column)
  {
      for (int i = 1; i &lt;= row; i++)
      if (queens[row - i] == column // Check column
          || queens[row - i] == column - i // Check upper left diagonal
          || queens[row - i] == column + i) // Check upper right diagonal
          return false; // There is a conflict
      return true; // No conflict
  }
  // Display the chessboard with eight queens
  void printResult()
  {
      cout &lt;&lt; "\n---------------------------------\n";
      for (int row = 0; row &lt; NUMBER_OF_QUEENS; row++)
      {
          for (int column = 0; column &lt; NUMBER_OF_QUEENS; column++)
              printf(column == queens[row] ? "| Q " : "| ");
          cout &lt;&lt; "|\n---------------------------------\n";
      }
  }
  // Search to place a queen at the specified row
  bool search(int row)
  {
      if (row == NUMBER_OF_QUEENS) // Stopping condition
          return true; // A solution found to place 8 queens in 8 rows
      for (int column = 0; column &lt; NUMBER_OF_QUEENS; column++)
      {
          queens[row] = column; // Place a queen at (row, column)
          if (isValid(row, column) &amp;&amp; search(row + 1))
              return true; // Found, thus return true to exit for loop
      }
      // No solution for a queen placed at any column of this row
      return false;
  }
  int main()
  {
      search(0); // Start search from row 0. Note row indices are 0 to 7
      printResult(); // Display result
      return 0;
  }
  </code></pre>
  
  <p>Now i want to modify it so it will take user input so it can start from rows 0-7.
  I've put something like this in the main function</p>
  
  <pre><code>int row, col = 0;
  cout &lt;&lt; "Enter a row number from 0-7 ";
  cin &gt;&gt; row;
  search(row);// Start search from row 0. Note row indices are 0 to 7
  bool yas = isValid(row, col);
  cout &lt;&lt; yas;
  printResult(); // Display result
  return 0;
  </code></pre>
  
  <p>However when I run it, I keep getting a syntax error or false no matter what. Is there a better way to take user input in this or did I logically do this wrong?</p>