저는 C++을 처음 접했을뿐입니다. 며칠 동안 프로그래밍을 해봤지만 어리석은 것처럼 보일 수도 있습니다. 그러나 왜 배열이 올바르게 작동하지 않는지 확인할 수 있습니까? 이것은 내가 스도쿠 퍼즐을 해결할 수있는 프로그램의 시작이지만 그것을 해결하기 위해 사용하고있는 2D 배열이 올바르게 작동하지 않습니다. 잘,이 char 배열 코드에 어떤 문제가 있습니까?
#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;
은} 또한 나는 스도쿠 보드를 구축하는 쉬운 방법이있을 수 있다는 것을 알고 있어요,하지만 난 이미 하나의 작동 방식을 내 마음에서 볼 수 있고, 실패 할 경우 배우는 유일한 길은 실패에 의한 것입니다. 내가 알고 싶은 건 어레이가 잘못된 것입니다.
정확히 무엇이 잘못 되었나요? –
@Ben 문자가 전혀 출력되지 않습니다. 보시다시피, 추가 COUT를 추가했습니다. 나는 무작위 배열 값을 출력한다고 말했고 심지어 그렇게하지도 않았다. –
코드가 제대로 컴파일 된 것처럼 보입니다 ... http://codepad.org/tKPRn9rZ 무엇이 문제입니까? –