Sudoku Grid Array

Hey Guys, trying to figure out this problem...I have to make a sudoku game, and I am pretty far into it now. This is a snippet of my code, I am just trying to figure out if theres anyway to put the gridKnownSE 2 dim array in to the [ ] sections of my rowsCols arry. Any tips? I know theres a few stuff missing, but I've hit the brick wall here. I'm a beginner so simplicity helps :)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55

#include <iostream>
#include <ctime>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;


int main()
{
    cout << "_____________________________________________" << endl;
    string rowsCol[9][9];
    
 
    int gridKnownSE[9][9] =
    {
        {9,2,7,4,5,6,1,3,8},
        {3,5,8,1,7,2,6,9,4},
        {1,6,4,3,9,8,7,2,5},
        {4,1,3,5,2,7,8,6,9},
        {8,7,2,9,6,1,4,5,3},
        {5,9,6,8,4,3,2,7,1},
        {2,3,5,7,8,4,9,1,6},
        {6,4,1,2,3,9,5,8,7},
        {7,8,9,6,1,5,3,4,2}
    };
    
    //PRINTS ROWS COLUMNS 1-3
    for (int x = 0; x<3; x++) {
        for (int y = 0; y<3; y++){
            cout << rowsCol[x][y] <<"| [ ] [ ] [ ] |";
        } cout << endl; }

    //GRID SPLITTER
    cout << "|¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯|" << endl;
    
    //PRINTS ROWS COLUMNS 4-6
    for (int x = 3; x<6; x++) {
        for (int y = 0; y<3; y++){
            cout << rowsCol[x][y] << "| [ ] [ ] [ ] |";
        } cout << endl; }
    //GRID SPLITTER
     cout << "|¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯|" << endl;
   
    //PRINTS ROWS COLUMNS 7-9
    for (int x = 6; x<9; x++) {
        for (int y = 0; y<3; y++){
            cout << rowsCol[x][y] << "| [ ] [ ] [ ] |";
        } cout << endl; }
    
    //Grid Splitter
    cout << "¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯\n\n\n\n\n\n" << endl;

}
Last edited on
Change rowsCol to an integer array like gridKnownSE. Use 0 to represent an empty square. If course you'll have to add some code to print a space instead of the number when displaying a board.

BTW, this is an example of a more general issue: the difference between how you represent the data in the program and how you present the data to the user. People often make the mistake of have the representation and the presentation the same when it would be much easier to code them separately.
Topic archived. No new replies allowed.