用if elseif else无法运行

无法运行
#include

main() {
int x, y;
scanf("%d", &x);
if (x < 0) {
y = -1;
} else if (x == 0) {
y = 0;
} else (x > 0) {
y = 2 * x;
}
printf("%d", y);
return 0;
}

10 16 F:\bianyi\新文件1.cpp [错误] 期待 ';' 在此之前: '{' 符号

首先你要明白:
①因为你有返回值 return 0,所以main函数前面要加上int
例如:int main(){return 0;}
②ifelse  ifelse格式如下
if(判断条件)
{}
else  if(判断条件)
{}
esle
{}//前面两个都不满足就执行这个

else (x > 0) 错了 要么直接 else{} 要么 else if(){} 一定要符合 if(){}else if(){}else{}这种规范,不要else接括号判断

img

img


else后面不能有条件,else if才可以有条件
改成这样

img