[問題] Dev C++編碼錯誤訊息

看板C_and_CPP作者 (LTE student researcher)時間9年前 (2014/09/12 12:20), 9年前編輯推噓2(200)
留言2則, 2人參與, 最新討論串1/1
現在碩四(中間因病休學兩次Q@Q)因此對程式有些生疏 可以請大大們幫我看看嗎Orz 以下是我寫的論文模擬程式碼(關於LTE MTC的) #include<stdio.h> #include<iostream> #include<cmath> #include<stdlib.h> #include<time.h> #include<fstream> using namespace std; static int Total_MD= 5000.0;//Total MTC device static int Total_agent= 100.0;//Total agent static double p=54;//Total preamble int back_window=32;///Backoff window static double HAEQ_P=0.1;//HARQ retransmission probability for Msg. 3 and Msg. 4 int backoff=20;//Backoff Indicator struct device{ double UID;// RNTI int x, y; //coordinates double phase;// MSG1 MSG2 MSG3 MSG4 double traned_time;//transmitted time double next_trans;//send MSG1 when count to 0 double success_time;//record success time int picked_preamble;//record which preamble ue picked bool agent; //through agent or not }; struct agent{ int x, y; //coordinates int contention_time;//record success time bool selected; double phase;// MSG1 MSG2 MSG3 MSG4 double traned_time;//transmitted time double next_trans;//send MSG1 when count to 0 double success_time;//record success time int picked_preamble;//record which preamble ue picked }; double Nor (double mu, double sigma) // Normal distribution { double U1, U2, W, mult; static double X1, X2; static int call = 0; if (call == 1) { call = !call; return (mu + sigma * (double) X2); } do { U1 = -1 + ((double) rand () / RAND_MAX) * 2; U2 = -1 + ((double) rand () / RAND_MAX) * 2; W = pow (U1, 2) + pow (U2, 2); } while (W >= 1 || W == 0); mult = sqrt ((-2 * log (W)) / W); X1 = U1 * mult; X2 = U2 * mult; call = !call; return (mu + sigma * (double) X1); } int randint(int low, int up) { return (int)((rand() / (RAND_MAX+1.0)) * (up - low + 1.0) + low); } int main() { double success_ratio=0; //MD's RACH success ratio int count_MD=0; fstream outputfile; outputfile.open("./RACH_agent100_MD5000_result.txt",ios::out | ios::trunc); device MD[Total_MD]; agent agent[Total_agent]; srand(time(0)); for(int i=0;i<(Total_MD-count_MD);i++)//initil all MD { srand(time(0)); MD[i].phase=0; MD[i].traned_time=0; MD[i].next_trans=0; MD[i].success_time=0; MD[i].x=Nor(randint(2,5),randint(3,9)); MD[i].y=Nor(randint(2,5),randint(2,9)); MD[i].x= Nor(rand(),randint(1,5)%randint(3,8)); MD[i].agent=false; srand(time(0)); MD[i].y=Nor(rand(),rand()); } for(int i=0;i<Total_agent;i++)//initial all agent { srand(time(0)); agent[i].x=Nor(rand(),rand()); srand(0); agent[i].y=Nor(rand(),rand()); agent[i].contention_time=0; agent[i].selected=true; agent[i].phase=0; agent[i].traned_time=0; agent[i].success_time=0; } int count=0; // 計數有透過agent的MD for(int i=0;i<Total_agent;i++) { double d = (agent[i].x - MD[i].x) * (agent[i].x - ((/*sqare this*/d = MD[i].x + agent[i].y - MD[i].y) * d)); //2D平面distance d=sqrt(d); if(d==0) { MD[i].agent=true; //有透過agent count++; } for(i=0;i<count; i++) //not agent but canditate { agent[i].phase=0; agent[i].traned_time=0; agent[i].next_trans=0; agent[i].success_time++; } int countagent; //離eNB很近 for(i=0;i<Total_MD;i++) { for(int i=0;i<Total_agent;i++) { double dist = (agent[i].x - MD[i].x)//distance * (agent[i].x - ((/*sqare this*/d = MD[i].x + agent[i].y - MD[i].y) * d)); double d =(agent[i].x -MD[i].x) *(agent[i].x-((/*sqare this*/d = MD[i].x + agent[i].y - MD[i].y) * d)); d= sqrt(d); if(d==0)//坐落在eNB上 { if(d<0) { agent[i].contention_time=0; agent[i].selected=true; countagent++; } } for(int i=0;i< count_MD;i++) //MD neihbor has agent, so use RACH { MD[i].phase=0; MD[i].next_trans=0; MD[i].success_time++; MD[i].traned_time=0; } cout<< countagent << endl; } 我的錯誤訊息是顯示在最後一行 錯誤訊息是這個 [Error] expected '}' at end of input 可以請大大們幫我看看嗎Orz 上網google都只有英文的... -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 60.248.162.154 ※ 文章網址: http://www.ptt.cc/bbs/C_and_CPP/M.1410495656.A.9E1.html

09/12 12:23, , 1F
大括號沒成對之類的問題吧
09/12 12:23, 1F

09/12 12:32, , 2F
在main裡面少了三個 } ,{}沒有成對
09/12 12:32, 2F
謝謝 我再試試 ※ 編輯: filexchang (60.248.162.154), 09/12/2014 15:40:23
文章代碼(AID): #1K4dIedX (C_and_CPP)