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