楼主,这个是我修改过的;#include <stdio.h>
#include <stdlib.h>
int main(void){
int score=0;
printf(";输入你的成绩(score):_");
scanf("%d",&score);
if (score<60){
printf("你的得分是:E\n");
getchar();
}
else if(score>=60 && score <70){
printf("你的得分是:D\n");
getchar();
}
else if(score>=70 && score<80){
printf("你的得分是:C\n");
getchar();
}
else {
printf("\n数据异常 或,输入数值超出验证范围\n请重式查询;\n");
getchar();
exit(0);
}
return 0;
}
这个是你原本的,我只做了注释:#include <stdio.h>
/*if..else if...elsef if..else 格式
*她和if..if..else语句的差别在于:
*if..else if..else如果前面的执行了后面的就算符合条件也不会再执行
*if..if..else 就算前面的执行了后面的if只要符合条件还是会执行;
*共同点呢,都是如果上面的都不符合条件,才用else;
*/
void main()//建议使用 int main(void)格式;
{
int score;
printf("输入成绩:");
scanf("score=%d",&score);//这个在下面的一处解释;
printf("score=%d ;\n",score);
if (score<60)
{
printf("E\n");
}
else if((score>60||score==60) && score < 70)
//(score>60 || sore==60)有些繁琐了。直接(socre>=60);
//修改后的 if(score>=60 && socre <70){...}
{
printf("D\n");
}
else if(score<80)
//楼主这里永远不会执行的,看我给你的else if语句的解释;
//修改后的 if(score>=70 && score <80)
{
printf("C\n");
}
//建议楼主加个 return 0;如果是int main(void)的话;
}
//最后呢,楼主应该学会使用网络,可以去 各种百科查询下各种语句和函数的解释;
//如果楼主英语不错的话,可以去msdn看看或者某些开源的论坛;
然后是关于你的scanf();#include <stdio.h>
void main(){
int score=0;
printf("输入成绩:");
scanf("score=%d",&score);
printf("score的值是:%d ;\n",score);
return 0;
}
//[截图]对于楼主的scanf()函数;楼主在控制台应该这么写才行,额,似乎有些麻烦!
好吧,这个运行结果看这里
http://bbs.fishc.com/home.php?mo ... lbum&picid=6571
|