私は C++ の初心者で、プログラミングを始めてまだ数日なので、ばかげているように思えるかもしれませんが、私の配列が正しく動作しない理由を見つけていただけますか? これは、数独パズルを解くために設計しているプログラムの始まりですが、それを解くために使用している 2D 配列が正しく機能していません。
#include <iostream>
#include <string>
using namespace std;
int main () {
char dash[9][9];
for (int array=0; array<9; array++) {
for (int array2=0; array2<9; array2++) {
dash[array][array2]=array2;
cout << dash[array][array2];
}
}
cout << dash[1][4] << endl; //This is temporary, but for some reason nothing outputs when I do this command.
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=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=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;
return 0;
}
また、数独ボードをもっと簡単に組み立てる方法があるかもしれないことは承知していますが、これがどのように機能するかはすでに頭の中にあります。失敗した場合、学習する唯一の方法は失敗することです。私が知りたいのは、配列の何が問題なのかということだけです。