# Problem with arrays C++



## GSquadron (Sep 6, 2011)

Hi guys!
I have read a lot about arrays and it comes a point where you get stuck!
So i created a sudoku, but now i want to print in the screen when the user
enters a wrong number.
For example, if the number exists in the row i want to show a warning it is in the row
If the number exists in the column i want to show a warning it is in the column
So far i made a coding but it is wrong because gets repeated the warning like
14 times or maybe more. It depends
This is the code:


```
for(int i = 0; i < 9; i++){
          if(sudokuplayer[row][i] != sudoku1[row][i]) cout << "\n Warning! This number is in the row";
          if(sudokuplayer[i][column] != sudoku1[i][column]) cout << "\n Warning! This number is in the column ";
          }
```

Pls help!


----------



## caleb (Sep 6, 2011)

Program needs to now the solution before the user so why are you checking in a loop when it should check upon every entry.


----------



## ctrain (Sep 6, 2011)

you need to start getting on good terms with your debugger, it will make things so much easier than playing guessing games.


----------



## GSquadron (Sep 6, 2011)

caleb said:


> Program needs to now the solution before the user so why are you checking in a loop when it should check upon every entry.



The solution is [sudoku1] and the player is [sudokuplayer]
That is the problem how to get it check in the row and column the player choose?
The cin for row is row and for column is column i don't understand why it is wrong :S
I have already made the sudoku work right.
All the program works perfect, the problem is
that with the loop i did, it shows a lot of warnings.
Even if your number is wrong only in the row,
it shows the warning in columns too!


@ctrain
i think this is the last time i will work on this sudoku i got angry with it!


----------



## Kreij (Sep 6, 2011)

You want to see if the sudokuplayer is the same as the sudoku1?
You are using an inequality (does not equal) statement, so every row and column that does not match the players input is producing the message.


----------



## GSquadron (Sep 6, 2011)

Kreij said:


> You want to see if the sudokuplayer is the same as the sudoku1?
> You are using an inequality (does not equal) statement, so every row and column that does not match the players input is producing the message.



#include <assert.h>
(Sudoku1 == Sudokuplayer) // I already know this, because of the assert library i added 

Now the problem is:
I want to know if the number the user puts in, is already in the row||column
For the second sentence you are right.
How do i make it only for the row and column the number is in?
So my idea is writting like this:
number != sudoku1_;
But, ISO C++ forbids pointer and integer comparison and this is only the row!_


----------



## Kreij (Sep 6, 2011)

Get the number that the player entered and also the row and column where he entered it.
Write a method for row checking that returns a boolean based on the results (found or not).
If the row check fails print error and return.
If the row check passes, call a column check method and do the same thing.
If both return success, the number entered was valid for the location.


----------



## GSquadron (Sep 6, 2011)

I tried doing it but didnt get far. Still i cannot find a fix


----------



## xbonez (Sep 6, 2011)

When a conflict is found within the for loop, you should break out of it. 


```
for(int i = 0; i < 9; i++)
{
	if(sudokuplayer[row][i] != sudoku1[row][i])
	{
		cout << "\n Warning! This number is in the row";
		break;
	}
	if(sudokuplayer[i][column] != sudoku1[i][column]) 
	{
		cout << "\n Warning! This number is in the column ";
		break;
	}
}
```


----------

