I am needing some help with my CS114 project. I am not expecting people here to do it for me just to help me with it.

The project is to do a Sudoku game with a 2d array (9x9) and read in a txt file that the instructor has supplied.

The txt file will have the nearly completed sudoku board.

I am having trouble reading the txt file into the 9x9 array

also, the output is confusing me

they want the board to be displayed in this manner ::


1 2 3 | 1 2 3 | 1 2 3
4 5 6 | 4 5 6 | 4 5 6
7 8 9 | 7 8 9 | 7 8 9
-----------------------
1 2 3 | 1 2 3 | 1 2 3
4 5 6 | 4 5 6 | 4 5 6
7 8 9 | 7 8 9 | 7 8 9
-----------------------
1 2 3 | 1 2 3 | 1 2 3
4 5 6 | 4 5 6 | 4 5 6
7 8 9 | 7 8 9 | 7 8 9
-----------------------

any help would be AMAZING and i kinda need it ASAP :)

thanks guys!

Can you be a little more specific in your problem with it? What about it is confusing you, or do you have code of your problem?

we are to write the entire code..here is the project
"Your Sudoku class should have a constructor, and a “read” function that reads in the file “Sudoku_game.txt,” a 9 by 9 matrix of digits from 0 to 9. (Zero indicates that no number has been put in that cell.) Your class should also have a print function, a test for whether the current state of the game is one that cannot work (violating some of the constraints, such as two 3‟s in the same box), a test to tell whether all the cells have been filled with a number, and a function that would allow a player to enter numbers in the open cells of the game. The main function should create an empty game, read a file into the game, print the current state of the game board, and then allow the player to add numbers (using row and column numbers) to complete the puzzle. After each number entered, the game should decide if the game is still winnable (that is, whether any of the constraints have already been violated.) If the last number entered won‟t work, print an error message and change the number back to zero. If the player successfully completes the game, entering the last number without violating the rules, the program should print a congratulatory message and quit. If the last cell is filled with a number, but the solution is not correct, the game should print a sympathetic message."

but i am starting small..and right now just trying to get the board to print out.
the txt file they give us has this:
"6 5 9 4 1 3 2 8 7
7 4 3 2 9 8 1 6 5
1 8 2 5 6 7 9 4 3
9 1 4 3 2 5 8 7 6
3 7 8 6 4 9 5 1 2
2 6 5 7 8 1 4 3 9
4 3 7 1 5 2 6 9 8
5 9 1 8 3 6 7 2 4
0 0 0 0 0 0 0 0 0
"
where the "0" are suppose to be blank places to be filled in.

how would i get this txt document to print out in the manner i mentioned in my previous thread.

we are to write the entire code..here is the project
"Your Sudoku class should have a constructor, and a “read” function that reads in the file “Sudoku_game.txt,” a 9 by 9 matrix of digits from 0 to 9. (Zero indicates that no number has been put in that cell.) Your class should also have a print function, a test for whether the current state of the game is one that cannot work (violating some of the constraints, such as two 3‟s in the same box), a test to tell whether all the cells have been filled with a number, and a function that would allow a player to enter numbers in the open cells of the game. The main function should create an empty game, read a file into the game, print the current state of the game board, and then allow the player to add numbers (using row and column numbers) to complete the puzzle. After each number entered, the game should decide if the game is still winnable (that is, whether any of the constraints have already been violated.) If the last number entered won‟t work, print an error message and change the number back to zero. If the player successfully completes the game, entering the last number without violating the rules, the program should print a congratulatory message and quit. If the last cell is filled with a number, but the solution is not correct, the game should print a sympathetic message."

but i am starting small..and right now just trying to get the board to print out.
the txt file they give us has this:
"6 5 9 4 1 3 2 8 7
7 4 3 2 9 8 1 6 5
1 8 2 5 6 7 9 4 3
9 1 4 3 2 5 8 7 6
3 7 8 6 4 9 5 1 2
2 6 5 7 8 1 4 3 9
4 3 7 1 5 2 6 9 8
5 9 1 8 3 6 7 2 4
0 0 0 0 0 0 0 0 0
"
where the "0" are suppose to be blank places to be filled in.

how would i get this txt document to print out in the manner i mentioned in my previous thread.

You need to post some code. You need a 2-D array of int and you need a function that reads in the data and you need a function that displays. Here's a skeleton that may help get you started.

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

void DisplayBoard (int grid[][9])
{
     // display grid.  Use nested for-loop     
}

void ReadFromFile (string filename, int grid[][9])
{
     // create ifstream
     // open ifstream with filename
     // read from file into grid using nested for-loop
     // close ifstream
}

int main ()
{
    int grid[9][9];
    string filename = "Sudoku_game.txt"; 
    ReadFromFile (filename, grid);
    DisplayBoard (grid);
    return 0;
}

ok for my void DisplayBoard function i have this :

void DisplayBoard (int grid[9][9]) // display grid. use nested for-loop
{
     cout << "\t+---+---+---+" << endl;
    for (int a=0; a<9; a++) {
        cout << "\t| ";
        for (int b=0; b<9; b++)
            cout << grid[a][b] << " | ";
        cout << endl;
        cout << "\t+---+---+---+" << endl;
    }

but when it displays it has "-858993460" in each area...?

my ultimate goal is to have the txt document provide the numbers to go in each block on the game board

Edited 3 Years Ago by mike_2000_17: Fixed formatting

ok for my void DisplayBoard function i have this :

void DisplayBoard (int grid[9][9]) // display grid. use nested for-loop
{
     cout << "\t+---+---+---+" << endl;
    for (int a=0; a<9; a++) {
        cout << "\t| ";
        for (int b=0; b<9; b++)
            cout << grid[a][b] << " | ";
        cout << endl;
        cout << "\t+---+---+---+" << endl;
    }

but when it displays it has "-858993460" in each area...?

my ultimate goal is to have the txt document provide the numbers to go in each block on the game board

Code tags:

// paste code here

This function looks OK. Are you initializing grid anywhere?

Edited 3 Years Ago by mike_2000_17: Fixed formatting

thats what im trying to get done now, is the grid display function.

i can have it display numbers if i do the code as this

int grid [9][9] = {1,2,3,4};

but im stumped on how i get the array to have the numbers that are set in the txt document provided.

am i close by thinking it is done this way.

ifstream in("sudoku_game.txt");

int grid[9][9] = "sudoku_game.txt");

THANKS FOR THE HELP!


am i close by thinking it is done this way.

ifstream in("sudoku_game.txt");

int grid[9][9] = "sudoku_game.txt");

THANKS FOR THE HELP!

No, that is not close.

http://www.cplusplus.com/doc/tutorial/files.html

The general idea is this. See my prior post on the ReadFile function and the tutorial above. That's the idea. Use my program as a skeleton.

This line is fine:

ifstream in("sudoku_game.txt");

This line isn't:

int grid[9][9] = "sudoku_game.txt");

This is better:

ifstream in("sudoku_game.txt");
for (i = ?;?;?)
{
     for (j = ?;?;?)
     {
         in >> grid[i][j];
     }
}
in.close ();

No, that is not close.

http://www.cplusplus.com/doc/tutorial/files.html

The general idea is this. See my prior post on the ReadFile function and the tutorial above. That's the idea. Use my program as a skeleton.

This line is fine:

ifstream in("sudoku_game.txt");

This line isn't:

int grid[9][9] = "sudoku_game.txt");

This is better:

ifstream in("sudoku_game.txt");
for (i = ?;?;?)
{
     for (j = ?;?;?)
     {
         in >> grid[i][j];
     }
}
in.close ();

so far i have this as my printBoard

int a,b;
	int grid[9][9];

	ifstream gameBoard;
	gameBoard.open("sudoku_game.txt");
	
	gameBoard >> grid[9][9];
		
	
	gameBoard.close();

	for (int a=0; a<9; a++) {

		cout << "\t| ";
	}
	
		
	for (int b=0; b<9; b++){
			
			cout << grid[a][b] << " | ";
		cout << endl;
		cout << "\t-------------------------------" << endl;
	}

but it still isnt printing out the numbers in the txt document.

so far i have this as my printBoard

int a,b;
	int grid[9][9];

	ifstream gameBoard;
	gameBoard.open("sudoku_game.txt");
	
	gameBoard >> grid[9][9];
		
	
	gameBoard.close();

	for (int a=0; a<9; a++) {

		cout << "\t| ";
	}
	
		
	for (int b=0; b<9; b++){
			
			cout << grid[a][b] << " | ";
		cout << endl;
		cout << "\t-------------------------------" << endl;
	}

but it still isnt printing out the numbers in the txt document.

See my prior post. You need the nested for-loop:

ifstream in("sudoku_game.txt");
for (i = ?;?;?)
{
     for (j = ?;?;?)
     {
         in >> grid[i][j];
     }
}
in.close ();

This is illegal:

gameBoard >> grid[9][9];

grid doesn't have an index of 9. It has indexes of 0 through 8 due to this declaration:

int grid[9][9];

grid[n][n] has legal indexes from grid[0][0] through grid[n-1][n-1] in C++. You're going to get a segmentation fault.

See my prior post. You need the nested for-loop:

ifstream in("sudoku_game.txt");
for (i = ?;?;?)
{
     for (j = ?;?;?)
     {
         in >> grid[i][j];
     }
}
in.close ();

This is illegal:

gameBoard >> grid[9][9];

grid doesn't have an index of 9. It has indexes of 0 through 8 due to this declaration:

int grid[9][9];

grid[n][n] has legal indexes from grid[0][0] through grid[n-1][n-1] in C++. You're going to get a segmentation fault.

ok i added in the nested for-loops..and i have an array printing out..but it is still blank.

here is my code:

{
	int i,j;
	int grid[9][9];

	ifstream gameBoard;
	gameBoard.open("sudoku_game.txt");
	for (i=0;i<10;i++)
	{
		cout << "\t| ";
		for (j=0;j<10;j++)
		{
			cout << " | ";
			gameBoard >> grid[i][j];
			
			
		
		}
	}
		
	
	gameBoard.close();

	
}

none of the #s in the sudoku_game.txt file are coming through to the command prompt

ok i added in the nested for-loops..and i have an array printing out..but it is still blank.

here is my code:

{
	int i,j;
	int grid[9][9];

	ifstream gameBoard;
	gameBoard.open("sudoku_game.txt");
	for (i=0;i<10;i++)
	{
		cout << "\t| ";
		for (j=0;j<10;j++)
		{
			cout << " | ";
			gameBoard >> grid[i][j];
			
			
		
		}
	}
		
	
	gameBoard.close();

	
}

none of the #s in the sudoku_game.txt file are coming through to the command prompt

Post the entire program.

Post the entire program.

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

void DisplayBoard (int grid[][9]) // display grid. use nested for-loop
{
     cout << "\t+---+---+---+" << endl;
	for (int a=0; a<9; a++) {
		cout << "\t| ";
		for (int b=0; b<9; b++)
			cout << grid[a][b] << " | ";
		cout << endl;
		cout << "\t+---+---+---+" << endl;
	}
}

void ReadFile (string filename, int grid[][9])
{
    int i,j;
	int array[9][9];

	ifstream in("sudoku_game.txt");//open ifstream with filename
	if(!in){
	cout << "cannot open file.\n";
	
}


	for(i=0; i<9; i++) //show values read from file
	{ 
	for (j=0; j<=i; j++)
	cout << array[i][j] << endl;
	}

in.close();//close ifstream
     
     
}

int main (){
	int i,j;
	int grid[9][9];

	ifstream gameBoard;
	gameBoard.open("sudoku_game.txt");
	for (i=0;i<10;i++)
	{
		cout << "\t| ";
		for (j=0;j<10;j++)
		{
			cout << " | ";
			gameBoard >> grid[i][j];
			
			
		
		}
	}
		
	
	gameBoard.close();

	
}
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

void DisplayBoard (int grid[][9]) // display grid. use nested for-loop
{
     cout << "\t+---+---+---+" << endl;
	for (int a=0; a<9; a++) {
		cout << "\t| ";
		for (int b=0; b<9; b++)
			cout << grid[a][b] << " | ";
		cout << endl;
		cout << "\t+---+---+---+" << endl;
	}
}

void ReadFile (string filename, int grid[][9])
{
    int i,j;
	int array[9][9];

	ifstream in("sudoku_game.txt");//open ifstream with filename
	if(!in){
	cout << "cannot open file.\n";
	
}


	for(i=0; i<9; i++) //show values read from file
	{ 
	for (j=0; j<=i; j++)
	cout << array[i][j] << endl;
	}

in.close();//close ifstream
     
     
}

int main (){
	int i,j;
	int grid[9][9];

	ifstream gameBoard;
	gameBoard.open("sudoku_game.txt");
	for (i=0;i<10;i++)
	{
		cout << "\t| ";
		for (j=0;j<10;j++)
		{
			cout << " | ";
			gameBoard >> grid[i][j];
			
			
		
		}
	}
		
	
	gameBoard.close();

	
}

ok i added in the nested for-loops..and i have an array printing out..but it is still blank.

Your array is NOT printing out. You never call either function. All the work is being done in main. Look at my skeleton and notice how and where I put the function calls in (that's if you want them to be in functions). You need to change the for loops in main from 10 to 9. You cannot have an index of 9. They must range from 0 to 8. I would personally have the work done in the functions as I originally suggested, in which case get rid of the array called array . You already have one called grid that you are passing to the function. That's what you want. Use grid , not array .

You should also format the code. Right now it's really hard to tell where one block of code begins and ends. Keep in mind that a tab on Daniweb takes 8 spaces, so often if you use tabs AND spaces on your IDE, it won't look right when you post here. Best to just use spaces.

Your array is NOT printing out. You never call either function. All the work is being done in main. Look at my skeleton and notice how and where I put the function calls in (that's if you want them to be in functions). You need to change the for loops in main from 10 to 9. You cannot have an index of 9. They must range from 0 to 8. I would personally have the work done in the functions as I originally suggested, in which case get rid of the array called array . You already have one called grid that you are passing to the function. That's what you want. Use grid , not array .

You should also format the code. Right now it's really hard to tell where one block of code begins and ends. Keep in mind that a tab on Daniweb takes 8 spaces, so often if you use tabs AND spaces on your IDE, it won't look right when you post here. Best to just use spaces.

ok i got it reading the files correctly, but now im just having problem with the formatting. in my first post i showed how it should output.any help would be great.

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

void DisplayBoard (int grid[][9]) // display grid. use nested for-loop
{
	int i,j;
    
	for (i=0;i<9;i++)
	{
		cout << "\t| ";
		for (j=0;j<9;j++)
		{
			cout << " | ";
			cout << grid[i][j];
		}
	}
}

void ReadFile (string filename, int grid[][9]){
	int i,j;
	ifstream gameBoard;					 //create ifstream
	gameBoard.open("sudoku_game.txt"); //open ifstream with filename

	if(!gameBoard){
	cout << "cannot open file.\n";
	}

	for (i=0;i<9;i++){
		for(j=0;j<9;j++){

	gameBoard >> grid[i][j];
		}
	}

	gameBoard.close();  //close ifstream  

}



int main (){

	int grid[9][9];
    string filename = "sudoku_game.txt"; 
    ReadFile (filename, grid);
    DisplayBoard (grid);
    return 0;

}
void DisplayBoard (int grid[][9]) // display grid. use nested for-loop
{
	int i,j;
    
	for (i=0;i<9;i++)
	{
		cout << "\t| ";
		for (j=0;j<9;j++)
		{
			cout << " | ";
			cout << grid[i][j];
		}
	}
}
1 2 3 | 1 2 3 | 1 2 3
4 5 6 | 4 5 6 | 4 5 6
7 8 9 | 7 8 9 | 7 8 9
-----------------------
1 2 3 | 1 2 3 | 1 2 3
4 5 6 | 4 5 6 | 4 5 6
7 8 9 | 7 8 9 | 7 8 9
-----------------------
1 2 3 | 1 2 3 | 1 2 3
4 5 6 | 4 5 6 | 4 5 6
7 8 9 | 7 8 9 | 7 8 9
-----------------------

You are on the right track, but you need to add a little more. Currently you have two for-loops that go from 0 to 8. You may want to either keep that or you may want to add some more for-loops. If you keep the two for-loops, add some if statements. For example:

for (int i = 0; i < 9; i++)
{
     for (int j = 0; j < 9; j++)
     {
          if (j == 3 || j == 6)
              cout << '|';  // only display this when j is 3 or 6

          cout << grid[i][j];
     } 
}

You need to display a line return ( cout << endl ) in there too somewhere. Right now it's one big line. You also need to display the line of dashes for some lines, but not others. Again, an if statement will do you well here. Same design, just add some if statements that display under certain circumstances and don't display otherwise.

thanks for the help so far! you are amazing!

but now i am to the meat of the project.

here is my code so far

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

class Sudoku {
public:
private:


};
void DisplayBoard (int grid[][9]) // displays grid
{
	int i,j,n;
   
	for (i=0;i<9;i++)
	{
		if (i == 3 || i == 6){
			cout << endl;
		cout << "--------------------";}

		cout << " " << endl;
		
		for (j=0;j<9;j++)
		{
		   if (j == 3 || j == 6){
			cout << "|";}

			cout << " ";
			
			cout << grid[i][j];
		}
	}
}

void ReadFile (string filename, int grid[][9]){
	int i,j;
	ifstream gameBoard;					 //create ifstream
	gameBoard.open("sudoku_game.txt");  //open ifstream with filename

	if(!gameBoard){			//ends program if file cant be read
	cout << "cannot open file.\n";
	}

	for (i=0;i<9;i++){
		for(j=0;j<9;j++){

	gameBoard >> grid[i][j];
		}
	}

	gameBoard.close();  //close ifstream  

}



int main (){
	int row,col,num;
	int grid[9][9];
    string filename = "sudoku_game.txt"; 
	
    ReadFile (filename, grid);
    DisplayBoard (grid);
	cout << endl;
	cout << endl;

	cout << "Enter a Number (r,c,n): ";
	cin >> row >> col >> num;
    return 0;

}

and these are the instructions:
"
Your Sudoku class should have a constructor, and a “read” function that reads in the file “Sudoku_game.txt,” a 9 by 9 matrix of digits from 0 to 9. (Zero indicates that no number has been put in that cell.) Your class should also have a print function, a test for whether the current state of the game is one that cannot work (violating some of the constraints, such as two 3‟s in the same box), a test to tell whether all the cells have been filled with a number, and a function that would allow a player to enter numbers in the open cells of the game."

Well, you need to stick the two functions inside your class as methods, as well as the grid[][] variable as a data memebr of the class. You may or may not decide to add the filename and/or ifstream as class variables. Right now nothing is in the class. Stick what you have into the class, get it to work, then start adding the other stuff. Have a main method that creates a class object and calls the class constructor.

ok i am REAL close i can feel it

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

class Sudoku {
public:
	int grid[9][9];


	void DisplayBoard () // displays grid
{
	int i,j,n;
   
	for (i=0;i<9;i++)
	{
		if (i == 3 || i == 6){
			cout << endl;
		cout << "--------------------";}

		cout << " " << endl;
		
		for (j=0;j<9;j++)
		{
		   if (j == 3 || j == 6){
			cout << "|";}

			cout << " ";
			
			cout << grid[i][j];
		}
	}
}

	void gameTest(){
	}

	void testCells(){
	}

	void playerInput(){
		while (1){
			DisplayBoard();
		int row,col,num;
		cout << endl;
		cout << endl;
		cout << "Enter a Number (r,c,n): ";
		cin >> row >> col >> num;
		row -= 1;
		col -= 1;
		if (checkRule(row,col))
		grid [row][col] = num;
		}
	}
	bool checkRule(int a, int b){
		for (int i=0;i<9;i++){
			if (grid [a][i] == grid [a][b] && i != b){
				return false;}
		}
		for (int j=0;j<9;j++){
			if (grid [j][b] == grid [a][b] && a != j){
				return false;}
		}
		int row = a / 3;
		int col = b / 3;
		if (row == 0 && col == 0){
			for (int i=0;i<3;i++)
				for (int j=0;j<3;j++)
					if (grid [i][j] == grid [a][b] && (i != a && j != b)){
						return false;}
		}
		if (row == 1 && col == 0){
			for (int i=3;i<6;i++)
				for (int j=0;j<3;j++)
					if (grid [i][j] == grid [a][b] && (i != a && j != b)){
						return false;}
		}
		if (row == 2 && col == 0){
			for (int i=6;i<9;i++)
				for (int j=0;j<3;j++)
					if (grid [i][j] == grid [a][b] && (i != a && j != b)){
						return false;}
		}
		if (row == 0 && col == 1){
			for (int i=0;i<3;i++)
				for (int j=3;j<6;j++)
					if (grid [i][j] == grid [a][b] && (i != a && j != b)){
						return false;}
		}
		if (row == 1 && col == 1){
			for (int i=3;i<6;i++)
				for (int j=3;j<6;j++)
					if (grid [i][j] == grid [a][b] && (i != a && j != b)){
						return false;}
		}
		if (row == 2 && col == 1){
			for (int i=6;i<9;i++)
				for (int j=3;j<6;j++)
					if (grid [i][j] == grid [a][b] && (i != a && j != b)){
						return false;}
		}
		if (row == 0 && col == 2){
			for (int i=0;i<3;i++)
				for (int j=6;j<9;j++)
					if (grid [i][j] == grid [a][b] && (i != a && j != b)){
						return false;}
		}
		if (row == 1 && col == 2){
			for (int i=3;i<6;i++)
				for (int j=6;j<9;j++)
					if (grid [i][j] == grid [a][b] && (i != a && j != b)){
						return false;}
		}
		if (row == 2 && col == 2){
			for (int i=6;i<9;i++)
				for (int j=6;j<9;j++)
					if (grid [i][j] == grid [a][b] && (i != a && j != b)){
						return false;}
		}
		return true;
	}


	void ReadFile (string filename){
	int i,j;
	ifstream gameBoard;					 //create ifstream
	gameBoard.open("sudoku_game.txt");  //open ifstream with filename

	if(!gameBoard){			//ends program if file cant be read
	cout << "cannot open file.\n";
	}

	for (i=0;i<9;i++){
		for(j=0;j<9;j++){

	gameBoard >> grid[i][j];
		}
	}

	gameBoard.close();  //close ifstream  

}



};





int main (){
	int row,col,num;
    string filename = "sudoku_game.txt"; 
	Sudoku S =  Sudoku();

    S.ReadFile (filename);

	S.playerInput();
    return 0;

}

it prints out the board and asks for (r,c,n) ..once i input those numbers and press enter...it just reprints the same board

how do i get it to update the board?

Don't assume that it isn't updating the board. Add a debugging statement:

if (checkRule(row,col))
     grid [row][col] = num;
else
     cout << "checkRule returned false.\n";

Make sure, if and when the text above displays, that you intended for checkRule to return false. Make sure that one, your function call is correct, and two, your checkRule function is correct.

yea my checkRule function logic is messed up

i added that "ELSE" statement you told me to..and it popped up every time with any number i added

so i dunno,, im stumped and almost out of time..if you could give my checkRule function a look over and see any mess up's i would appreciate itt.. :)

yea my checkRule function logic is messed up

i added that "ELSE" statement you told me to..and it popped up every time with any number i added

so i dunno,, im stumped and almost out of time..if you could give my checkRule function a look over and see any mess up's i would appreciate itt.. :)

int row = a / 3;
		int col = b / 3;
		if (row == 0 && col == 0){
			for (int i=0;i<3;i++)
				for (int j=0;j<3;j++)
					if (grid [i][j] == grid [a][b] && (i != a && j != b)){
						return false;}
		}

Your last row flunks this test right away before you even start since it's all zeros:

for (int i=0;i<9;i++){
			if (grid [a][i] == grid [a][b] && i != b){
				return false;}

If 0 represents an unfilled cell, then having two zeros is not illegal, but you are not checking for that, so this function returns false if there is more than one zero. Do you want that? If not, add another condition to your if statements that says that the cell must not equal 0 to return false. Ditto with all of your other tests.

Comments
HE IS VERY PATIENT AND AMAZING

so something similar to

for (int i=0;i<9;i++){
			if ((grid [a][i] == grid [a][b] && i != b) != 0){
				return false;}

so something similar to

for (int i=0;i<9;i++){
			if ((grid [a][i] == grid [a][b] && i != b) != 0){
				return false;}

No. Like this:

if (grid[a][b] != 0 && grid [a][i] == grid [a][b] && i != b){
     return false;}

You can make it a little more efficient:

if (grid[a][b] != 0)
{
     for (int i=0;i<9;i++){
          if (grid [a][i] == grid [a][b] && i != b){
               return false;}
}
This article has been dead for over six months. Start a new discussion instead.