我得到了上面的错误。我用C语言编写代码,使用标准的gcc编译器(命令窗口)。下面是我的代码中有问题的部分。我没有看到任何错误,也许我的眼睛已经厌倦了看同样的东西。
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;
}
}
}
}发布于 2012-08-27 22:12:07
对于else,您不需要一个条件。当所有if上的条件都失败时,它就会执行。去掉括号中的东西,你就会好起来:
else {
...发布于 2012-08-27 22:11:33
... else if (r1 < r2) ...将是语句的条件形式,但由于第一个if有一个补充条件(r1 >= r2),一个简单的else可以做到这一点。
因此,您将拥有:
if (r1 >= r2){
leader-> price1 = p_max;
}
else {
leader -> price1 = p_max;
...发布于 2012-08-27 22:11:53
试着改变
else (r1 < r2) { //try to route s2至
else if (r1 < r2) { //try to route s2https://stackoverflow.com/questions/12143647
复制相似问题