Hey, I've got this code that scans a 3x3 section of a 9x9 array. Heres the code:

for (j=x; j<x+3; j++)
{
for (i=y; i<y+3; i++)
        {	
	if (array[i][j] == value)
	{			
	cout<< "Number already used in Section" << endl;
	}
					
	}
}

It works fine if you start from the top left corner of a section since it will search the within the 3x3, but anywhere else it will obviously add 3 to the coordinate you entered and will take the section as being part of a different section if that makes any sense. Not sure how to get around this, any help?

Recommended Answers

All 6 Replies

if think you need to add more limits.

you check for a value but you also need to check if its inside the borders.
like

if (array[i][j] == value && array[i][j] <= limit//for example

you have to create the limit for all the 4 sides

I was thinking that but that would only work if I knew what section was going to be chosen.

the array is 9x9 and you want to check 3x3 on it right? 3x3 isnt the area for checking?
or i understood wrong?

i dont think you need to know what section you would be chosen you only need to keep it inside there :)

if you explain better your problem?

Sorry, what I mean is, the area I need to search is 3x3 but the 3x3 section is determined by the user. So if the user selects (0,0) it will be the first 3x3 section. If the user selects (0,3) it will be the second. Making limits would only work for one of the sections. For instance, the (0,0) limits would be (0,0) (0,2) (2,0) and (2,2) which would be different for all the others.

i think you missunderstood the limits.

with the 2 fors you check the 3x3 area you want and it limit the area to 3x3
what i mean is to put if restrictions in case the user enter (8,8) and the 3x3 check exceeds the 9x9 array.

some examples:
user enter (0.0) 3x3 area = 0.0, 0.1, 0.2, 1.0, 1.1, 1.2, 2.0, 2.1, 2.2
user enter (4.5) 3x3 area = 4.5, 4.6, 4.7, 5.5, 5.6, 5.7, 6.5, 6.6, 6.7
user enter (7.8) 3x3 area = 7.8, 7.9, ? now what? thats what i mean

Sorry I dont really understand how that would work. Say the user enters (8,8), I need it to search the 3x3 starting from (6,6) but right know it would only search (8,8)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.