读书人

关于C语言变量使用有关问题

发布时间: 2012-03-18 13:55:39 作者: rapoo

关于C语言变量使用问题
#include<stdio.h>
void main(){
int year;
printf("Input a year:");
scanf("%d",&year);
if(year%4==0&&year%100!=0||year%400==0)
printf("%d年为闰年!\n",year);
else
printf("%d年不为闰年!\n",year);
int score;
printf("Input a score:");
scanf("%d",&score);
if(score<60)
printf("bad\n");
else if(score<70)
printf("pass\n");
else if(score<80)
printf("general\n");
else if(score<90)
printf("good\n");
else if(90<=score)
printf("excellent\n");
}
编译说score变量未定义
#include<stdio.h>
void main(){
int year;int score;
printf("Input a year:");
scanf("%d",&year);
if(year%4==0&&year%100!=0||year%400==0)
printf("%d年为闰年!\n",year);
else
printf("%d年不为闰年!\n",year);

printf("Input a score:");
scanf("%d",&score);
if(score<60)
printf("bad\n");
else if(score<70)
printf("pass\n");
else if(score<80)
printf("general\n");
else if(score<90)
printf("good\n");
else if(90<=score)
printf("excellent\n");
}
这样却可以,虽然是小问题,但心理有疑惑,在百度上面也没找到答案,希望哪位能够解释一下,谢谢

[解决办法]
估计你用的是VC6,太老了不支持c新标准。喜欢用IDE的话建议用code::blocks
[解决办法]
老的编译器,像Turbor C里变量的都声明都放在语句前面,就是函数的开头部分。
像gcc等这样的编译器默认就支持在中间定义变量,但默认仍不支持类似这样的语句for(int i; i……,gcc编译的时候可以加参数控制。

读书人网 >C语言

热点推荐