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;
}
首先你要明白:
①因为你有返回值 return 0,所以main函数前面要加上int
例如:int main(){return 0;}
②if ,else if,else格式如下
if(判断条件)
{}
else if(判断条件)
{}
esle
{}//前面两个都不满足就执行这个
else (x > 0) 错了 要么直接 else{} 要么 else if(){} 一定要符合 if(){}else if(){}else{}这种规范,不要else接括号判断