Sudoku, Generating number in a board.

Write your question here.
Hi everyone... I'm writing a program for sudoku puzzle. so I'm done creating the board. But my problem is I have no idea how to generate number inside in board. I need help.

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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
  Put the code you need help with here.
void main (){
	//Descriptions and genral ideas 
	cout << "WELCOME TO SUDOKU " << endl;
	cout << endl;

	cout << "RULES:    "<< endl;
	cout << endl;

	cout << "->You'll be given a 9x9 board with some numbers depending on which level of difficulty you choose to play."<< endl;
	cout << endl;

	cout << "->You have to arrange numbers from 1 to 9 so that a number shows up once in one row, one column and in a 3x3 box." << endl;
	cout << endl;

	cout << "So, let's get started" << endl;

	cout << endl;
	cout <<endl;



	char dash[9][9];
for (int array=0; array<9; array++) {
    for (int array2=0; array2<9; array2++) {
        dash[array][array2]='_';
    }
}
char row[9];
char column[9];
char num[81];

int length;
length=strlen(row);
//Replaces the _'s in the specified rows/columns and replaces them with the integer the user specified. 
for (int i=0; i<length; i++) {
    dash[row[i]][column[i]]=num[i];
}

//Builds the Sudoko board and outputs the full 9x9 array.
cout << "   0    1   2   3   4   5    6    7   8  " << endl;

cout << "-----------------------------------------" << endl;
int i=0;
for (int count=0; count<3; count++) {
	
    for (int count2=0; count2<3; count2++) {
        cout << "||_" << dash[count][count2*3] << "_|_" << dash[count][count2*3+1] << "_|_" << dash[count][count2*3+2] << "_";   
    }
        cout << "||" << i <<  endl;
		i++;
}
cout << "-----------------------------------------" << endl;
int j=3;
for (int count=3; count<6; count++) {
    for (int count2=0; count2<3; count2++) {
        cout << "||_" << dash[count][count2*3] << "_|_" << dash[count][count2*3+1] << "_|_" << dash[count][count2*3+2] << "_";   
    }
	cout << "||" << j << endl;
	j++;
}
cout <<"-----------------------------------------" << endl;
int z=6;
for (int count=6; count<9; count++) {
    for (int count2=0; count2<3; count2++) {
        cout << "||_" << dash[count][count2*3] << "_|_" << dash[count][count2*3+1] << "_|_" << dash[count][count2*3+2] << "_";   
    }
    cout << "||" << z << endl;
	z++;
}
cout << "-----------------------------------------" << endl;




	system("pause");
}
sounds like you need to assign each piece a number, and use a random number system to put them into some order. http://www.cplusplus.com/reference/cstdlib/rand/

Topic archived. No new replies allowed.