[問題] 雙層迴圈之問題

看板C_and_CPP (C/C++)作者 (LTE student researcher)時間11年前 (2014/09/16 10:18), 11年前編輯推噓4(4010)
留言14則, 5人參與, 最新討論串1/1
開發平台(Platform): (Ex: VC++, GCC, Linux, ...) GCC 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) cmath time.h 問題(Question): 編譯錯誤 餵入的資料(Input): agent[j].x MD[i].x agent[j].y MD[i].y (用normal distribution產生出的xy座標值) 預期的正確結果(Expected Output): 預期算出任兩點在平面上的距離 錯誤結果(Wrong Output): [Error] name lookup of 'j'changed for ISO 'for' scoping [-fpermissive] 程式碼(Code):(請善用置底文網頁, 記得排版) for(int i=0;i<Total_MD-countMD;i++) { for(int j=0;i<Total_agent;j++) //用agent的MD double d = (agent[j].x - MD[i].x)* (agent[i].x - ((/*sqare this*/d = MD[i].x + agent[j].y - MD[i].y) * d)); double d =(agent[j].x -MD[i].x); *(agent[j].x-((/*sqare this*/d = MD[i].x + agent[j].y - MD[i].y) * d)); 補充說明(Supplement): 這是一個模擬通訊論文的程式,距離上次寫這種類似的模擬程式大約有八年了 因此對程式有些生疏 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 60.248.162.154 ※ 文章網址: http://www.ptt.cc/bbs/C_and_CPP/M.1410833895.A.788.html ※ 編輯: filexchang (60.248.162.154), 09/16/2014 10:19:14

09/16 10:20, , 1F
第二個迴圈的大括號
09/16 10:20, 1F

09/16 10:20, , 2F
另外第二個迴圈你確定是要用i當判斷嗎? i<Total_agent
09/16 10:20, 2F
※ 編輯: filexchang (60.248.162.154), 09/16/2014 10:50:02

09/16 10:52, , 3F
不好意思,code沒貼完整,原始碼是有大括號的
09/16 10:52, 3F

09/16 10:53, , 4F
S大,請教你第二句話是什麼意思?不用i有甚麼差別嗎?
09/16 10:53, 4F

09/16 11:24, , 5F
沒有啦,只是想確定是要用j或是i當判斷,因為code不完整
09/16 11:24, 5F

09/16 11:25, , 6F
看不出來
09/16 11:25, 6F

09/16 11:27, , 7F
不重要的東西,不會影響編譯
09/16 11:27, 7F

09/16 11:32, , 8F
一個判斷agent 另一個就是MD囉
09/16 11:32, 8F
我試著把code放到網路上http://codepad.org/loHPHimB請大家幫我看看,感謝! ※ 編輯: filexchang (60.248.162.154), 09/16/2014 12:27:29

09/16 17:16, , 9F
先不論程式邏輯 我覺得應該有少括號 還有for掉在main外面
09/16 17:16, 9F

09/16 17:33, , 10F
有嗎?main外面的是function call 阿!
09/16 17:33, 10F

09/16 17:46, , 11F
請用4個空白...
09/16 17:46, 11F

09/16 17:53, , 12F
http://codepad.org/DIJXnjJk 好心一點幫你indent
09/16 17:53, 12F

09/16 17:53, , 13F
稍微用心就看得出來問題在哪吧
09/16 17:53, 13F

09/16 18:36, , 14F
內迴圈確定不會變成無窮迴圈嗎?
09/16 18:36, 14F
文章代碼(AID): #1K5vtdU8 (C_and_CPP)
文章代碼(AID): #1K5vtdU8 (C_and_CPP)