# Sudoku Problems in C++

Discussion in 'C++' started by Xodiox, Jun 19, 2006.

1. ### XodioxNew Member

Joined:
Jun 19, 2006
Messages:
11
1
Trophy Points:
0
Hi everyone. I have just started with programming in C++ a few weeks ago so I have not that much understanding of it. I have been given a project of making a Sudoku game,

I have got my code to randomly choose a number and check it against the other numbers in the same row and column but i can't get it to check against the other numbers in the subgrid.

Heres the main part of my code
Code:
```int bad;
int x;
int i1;
int j1;
int i;
int j;
int n [ROWS][COLS];

for (i = 0; i < ROWS; i++) {
for (j = 0; j < COLS; j++) {

do { x = rand()%9 +1; bad = 0;   // random number

for (i1 = 0; i1 < i; i1++)           // Checking against other numbers in the row
if (x == n[i1][j]) bad = 1;

for (j1 = 0; j1 < j; j1++)       // Checking against other numbers in the column
if (x == n[i][j1]) bad = 1;
n[i][j] = x; }
}

cout << "Sukodu Board:\n";
for (i = 0; i < ROWS; i++) {
for (j = 0; j < COLS; j++)
cout << n[i][j] << " ";  // Prints out the numbers
```
I hope that you can follow the code.

Thanks

saiprem likes this.

Joined:
Jul 12, 2004
Messages:
15,341
379
Trophy Points:
83

3. ### XodioxNew Member

Joined:
Jun 19, 2006
Messages:
11
1
Trophy Points:
0
I read that artical very carefully before making this thread, but I it is a good start none the less.

4. ### XodioxNew Member

Joined:
Jun 19, 2006
Messages:
11
1
Trophy Points:
0
I have been testing different sizes of boards and the biggest it can do is a 6 * 6 because any bigger and it does not display anything. I think that this is because it just takes too long to calculate which numbers can go to the different spaces.

Any ideas on how I can make it calculate faster so I can get a 9 * 9 board ?

Thanks for you help.

Joined:
Jul 13, 2010
Messages:
1