2012-08-27 56 views
1

我收到上述错误。我在C编码并使用标准的gcc编译器(命令窗口)。这是我的代码中有问题的部分。我没有看到任何错误,也许是我的眼睛累了看同样的事情预计';'之前的'{'令牌C代码

LEADER *call_leader(double st1, double st2, double incentive, double pdis) 
{ 
    LEADER *leader= (LEADER *)malloc(sizeof(LEADER)); 
    double shortest = MIN(st1, st2) ; //shortest station 
    if (shortest == st1 && s1 != 0){ //no congestion 
     leader->price1 = p_max; 
     leader->price2 = p_max; 
    } 

    if (shortest == st2 && s2 != 0){ //no congestion 
     leader->price1 = p_max; 
     leader->price2 = p_max; 
    } 

    if (shortest == st1 && s1 == 0){ //congestion at station 1 
     if (s2 != 0){ // no congestion at station 2, try to route 
      leader->price1 = p_max; 
      double cost_1 = shortest*pdrive + p_max; 
      double p2 = cost1 - st2*pdrive - (sqrt(pow((st2 - st1),2)))*pdis -  incentive; 
     if (p2 >= p_min){ 
      leader->price2 = p2; 
     }else{ 
      leader->price2 = p_min; 
     } 
    } 
    else if (s2 == 0){ 
     if (r1 >= r2){ // st1 less congestion 
      leader-> price1 = p_max; 
     } 
Problematic Line =>  else (r1 < r2) { //try to route s2 
      leader -> price1 = p_max; 
      double cost_1 = shortest*pdrive + p_max; 
      double p2 = cost1 - st2*pdrive - (sqrt(pow((st2 - st1),2)))*pdis - incentive; 
      if (p2 >= p_min){ 
       leader->price2 = p2; 
      } 
      else{ 
       leader->price2 = p_min; 
      } 
     } 

    } 
} 
+1

'else'不采用条件语句,你可能意味着'else if(r1 birryree

+1

我修复了你的格式。但为了将来的参考,尽量避免在代码块中使用制表符,因为它们可能会弄乱格式。 – Mysticial

回答

3

你并不需要一个条件else。它在所有if的条件失败时执行。删除的东西,如果括号,你会很好:

else { 
... 
3

... else if (r1 < r2) ...将是该语句的条件形式,但作为拳头if有一个互补的条件(r1 >= r2)简单else做它。

所以,你将有:

if (r1 >= r2){ 
    leader-> price1 = p_max; 
} 
else { 
    leader -> price1 = p_max; 
... 
3

尝试改变

else (r1 < r2) { //try to route s2 

else if (r1 < r2) { //try to route s2 
相关问题