鱼C论坛

 找回密码
 立即注册
查看: 4947|回复: 9

为什么运行时报错

[复制链接]
发表于 2013-1-9 14:52:43 | 显示全部楼层 |阅读模式
2鱼币
#include <stdio.h>
void main()
{
    int score;
scanf("%d",&score);
if(score<60)
{
  printf("your score is E\n");
}
else if ( (60<score||score==60)&&score>70)
{
  printf("your score is D\n");
}
else if ((70<score||70==score)&&score>80)
{
  printf("your score is C\n");
}
else if ( (80<score||80==score)&&score>90)
{
  printf("your score is B\n");
}
else if (90<score)
{
  printf("your score is A\n");
}
else if (score<0&&score>100)
{
  printf("error");
}
}





--------------------Configuration: tt - Win32 Debug--------------------
Compiling...
tt.c
D:\Cc\tt\tt.c(1) : error C2059: syntax error : '<'
执行 cl.exe 时出错.
tt.exe - 1 error(s), 0 warning(s)

小甲鱼最新课程 -> https://ilovefishc.com
发表于 2013-1-9 14:52:44 | 显示全部楼层
  1. #include <stdio.h>
  2. int  main()
  3. {
  4.     int score;
  5. scanf("%d",&score);
  6. if(score<60)
  7. {
  8.   printf("your score is E\n");
  9. }
  10. else if ( (60<score||score==60)&&score<70)//注意你的判别条件啊 ,下面也是
  11. {
  12.   printf("your score is D\n");
  13. }
  14. else if ((70<score||70==score)&&score<80)
  15. {
  16.   printf("your score is C\n");
  17. }
  18. else if ( (80<score||80==score)&&score<90)
  19. {
  20.   printf("your score is B\n");
  21. }
  22. else if (90>score&&score<100)
  23. {
  24.   printf("your score is A\n");
  25. }
  26. else if (score<0&&score>100)
  27. {
  28.   printf("error");
  29. }
  30. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2013-1-9 17:37:40 | 显示全部楼层
估计是汉字符号问题。。。
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2013-1-9 17:44:08 | 显示全部楼层

你的这个程序用
switch()
case :
效率会提高
如下例:
int n = score/10;
n=(n<=5?5:n);
switch(n)
{
       case 5:
                   printf("you score is E");
       case 6:
                   printf("you score is D");
        .............
   

}
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2013-1-9 18:16:46 | 显示全部楼层
else if ( (60<score||score==60)&&score>70)
{
  printf("your score is D\n");
}
else if ((70<score||70==score)&&score>80)
{
  printf("your score is C\n");
}
else if ( (80<score||80==score)&&score>90)
{
  printf("your score is B\n");
}
1:      你的80<score||80==score 可以写成 score<=80这种形式。
2:      你的算法错误(逻辑错误),仔细检查下判断语句!
3:      测试了下你的代码没什么问题,可以运行。
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2013-1-11 20:40:39 | 显示全部楼层
没有错误   我复制你的就能运行(估计是你先谢了一个其他代码,然后编译运行!然后又写了一个其他的代码,然后又编译运行,注意就是这里他会出错的)))还有 楼主  你的代码 写的不是很好啊!!我帮你改一下!!好凌乱啊!!!60<score||score==60就用score>=60,然后 (60<score||score==60)&&score>70就是score>=60 && score > 70!!!!!用&&???也就是score > 70是D????你代码写的也。。。。。。。。。算了, 不改了,自己改
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2013-1-12 16:48:53 | 显示全部楼层
编译器的不同会导致一些代码不能识别
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2013-1-13 15:37:18 | 显示全部楼层
首先你的代码急需改进,逻辑性不强。思维混乱,else后面的条件基本上都是错误的。请再看看大于小于的问题。谢谢!
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2013-1-19 17:54:58 | 显示全部楼层
你的所有else if里面语句判别条件都不对!!!
你的条件自己看看  意思是大于等于60或者大于70~~!!
要小心啊
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2013-1-19 17:55:51 | 显示全部楼层
else if ( (60<score||score==60)&&score>70)
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-8-9 12:14

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表