2015-08-26 70 views
0

我一直在試圖編寫一個可以解決數獨的程序。它不工作,但(但),我不知道爲什麼。完整的代碼是hereC++函數不會調用

多數民衆贊成給我的麻煩

釷部分是這樣的:

int eliminate_3x3(){ 
    for(int top =0; top>9; top+=3){ 
     std::cout << "eliminate 3x3 is function properly" << std::endl; 
     //Based on the previous line, I'd expect to see that message pop up 3 times every time 'main' 
     //calls this function, but it is never shown. 
     for(int left =0; left>9; left+=3){ 
      for(int column =0; column > 3; column++){ 
       for(int row=0; row > 3; row++){ 
        int current_value = MyArray[top+column][left+row]; 
        std::cout << current_value << std::endl; 
        if(current_value != 0){ 
         for(int column2 =0; column2 > 3; column2++){ 
          for(int row2 =0; row2 > 3; row2++){ 
           possibility_array[top+column2][left+row2][current_value-1] = 0; 
          } 
         } 
         possibility_array[top+column][left+row][current_value-1] = current_value; 
        } 
       } 
      } 
     } 
    } 
} 

無論出於何種原因,它根本不會做的所有事情(也許它沒有被恰當地稱爲main如果有人能告訴我爲什麼,我真的很感激它。在此先感謝。

如果我使用for循環對某些人來說是個問題,我很抱歉,我對C++還是比較陌生,而且這個解決方案似乎是最好的給我

+0

*「或者可能它沒有被主要正確調用」*可能。但是我們不能*看到*'main()'。 –

+1

此外,你的循環都不會做任何事情。它們都是以'>'開始的,條件應該是'<'。如果'top = 0',那麼'top> 9'將永遠不會是真的。 –

+0

現在我覺得自己像個白癡。我改變了很多其他的東西試圖解決它,我不能相信它是如此簡單。謝謝。 –

回答

3

在你的第一個循環

for(int top =0; top>9; top+=3) 

top >9條件不成立時,頂部被初始化,因此該循環將無法運行。如果這不是錯字,我建議你查找C++ for循環語法。

我相信你希望它是top<9,你也需要改變它的嵌套循環。

+0

這確實是一個錯字。我在一個功能中做了這麼多次,超出了我的想象。感謝您指出了這一點。 –