0

我正在做一个数独游戏。我把板子做好了。但问题是我真的很困惑如何在这个框中生成数字。因为它是一个 Char 数组。但我想生成整数。我需要帮助。

这就是我到目前为止所拥有的。

enter code here
#include <iostream>
#include <string>
#include <cstring>

using namespace std;


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 << "-------------------------------------" << endl;
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 << "|" << endl;
}
cout << "-------------------------------------" << endl;
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 << "|" << endl;
}
cout <<"-------------------------------------" << endl;
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 << "|" << endl;
}
cout << "-------------------------------------" << endl;




system("pause");
}
4

1 回答 1

0

您可以使用随机函数生成数字并将其转换为“char”,只需添加 48

于 2013-04-26T18:35:50.147 回答