Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   Sudoku Problems in C++ (http://www.go4expert.com/forums/sudoku-cpp-t909/)

 Xodiox 19Jun2006 18:26

Sudoku Problems in C++

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: CPP

`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;                }while (bad);        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

 shabbir 20Jun2006 11:21

Re: Sudoku Problems in C++

 Xodiox 20Jun2006 11:39

Re: Sudoku Problems in C++

I read that artical very carefully before making this thread, but I it is a good start none the less.

 Xodiox 20Jun2006 13:02

Re: Sudoku Problems in C++

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.

 saiprem 28Jul2011 10:26

Re: Sudoku Problems in C++

Excuse me, can i view the source code of your program?i mean the total code

 All times are GMT +5.5. The time now is 22:43.