简单的if语句,怎么错了?!

来源:百度知道 编辑:UC知道 时间:2024/06/09 16:15:11
#include <math.h>
#include <stdio.h>
#include <conio.h>
void main()
{
long I,reward;
int c;
c=I/100000;
scanf("%ld",&I);
if(c<=1)
printf("r1=%ld",reward=0.1*I);
else
printf("r2=!");
}
显示Misplaced else

你的代码是从别的地方复制过来的吧,后面的有些空格可能编译器不认识,就造成 Misplaced else 问题。你把每一行的代码后面的空格都删除,再试试看。我的在VC 下的编译结果如下:
Compiling...
tt.c
c:\documents and settings\f1214421\桌面\新资料夹 (2)\tt.c(11) : warning C4244: '=' : conversion from 'double ' to 'long ', possible loss of data
c:\documents and settings\f1214421\桌面\新资料夹 (2)\tt.c(8) : warning C4700: local variable 'I' used without having been initialized

tt.obj - 0 error(s), 2 warning(s)

不明白,应该没什么问题,加上{}试试。
另外,l 没有初始化,最好不要用 c=I/100000

你好:
你的l没有初值,这样编译是通不过的,如果你非要这样做,你可以把它定义成为static类型,这样编译器会给他一个0的初值。