Sudoku Problems in C++

Xodiox's Avatar
Go4Expert Member
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
saiprem like this
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
See if Sudoku Solving Program Using 'C' may help you.
Xodiox's Avatar
Go4Expert Member
I read that artical very carefully before making this thread, but I it is a good start none the less.
Xodiox's Avatar
Go4Expert Member
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's Avatar, Join Date: Jul 2010
Newbie Member
Excuse me, can i view the source code of your program?i mean the total code