当前位置: 代码迷 >> C语言 >> 求成绩等级
  详细解决方案

求成绩等级

热度:198   发布时间:2006-05-14 12:57:00.0

写个1行完成判断的程序。
int main(int argc, char* argv[])
{
int intScore;
char cLevel;

printf("\nplease input an score:\n");
scanf("%d",&intScore);

cLevel = intScore < 60 ? 'E' : 'A' + 9 - (intScore-1)/10;
printf("score is %c\n", cLevel);
return 0;
}

[此贴子已经被作者于2006-5-14 13:13:10编辑过]


----------------解决方案--------------------------------------------------------
果然是越学越简单。
真是的。路漫漫长饿。。。
----------------解决方案--------------------------------------------------------
9楼的改法错了,if(x>=90 && x=<100)
k=1;
if(x>=80 && x=<90)
k=2;
if(x>=70 && x=<80)
k=3;
if(x>=60 && x=<70)
k=4;
if(x<60)
k=5;要改为if(x>=90 && x<=100)
k=1;
if(x>=80 && x=<90) //if(x>=80 && x<90)
k=2;
if(x>=70 && x=<80) //if(x>=70 && x<80)
k=3;
if(x>=60 && x=<70) //if(x>=60 && x<70)
k=4;
if(x<60)
k=5;
----------------解决方案--------------------------------------------------------
以下是引用走刀口→超在2006-5-14 12:40:00的发言:

#include<stdio.h>
main()
{ int score,mark;
printf("\nplease input an score:\n");
scanf("%d",&score);
mark=score/10;
switch(mark)
{
case 10:
case 9: printf("\nthe score belong to A !\n");break;
case 8: printf("\nthe score belong to B !\n");break;
case 7: printf("\nthe score belong to c !\n");break;
case 6: printf("\nthe score belong to D !\n");break;
case 5: printf("\nthe score belong to d !\n");break;
default:printf("error!");
}
}


mark=score/10;这句用得好
红色的应该为这样吧
case 5:
case 4:
case 3:
case 2:
case 1:
case 0: printf("\nthe score belong to D !\n");break;
见笑了


----------------解决方案--------------------------------------------------------
饿。对哦对哦~~~
这下搞大了。
下次注意下次注意!
----------------解决方案--------------------------------------------------------
以下是引用gaga在2006-5-14 12:49:00的发言:
你的程序我没有动就加个括号:

以下是引用xiaotan在2006-5-13 19:12:00的发言:

给100分制成绩,要求输出成绩等级‘A’,‘B’,‘C’,‘D’,‘E’。90分以上为‘A’,80-90为
‘B’,70-80为‘C’,60-70为‘D’,60分以下为‘E’。
#include<stdio.h>
#include<math.h>
main()
{
int x,k;

printf("\nplease input an score:\n");
scanf("%d",&x);
if(x>=90 && x=<100)
k=1;
if(x>=80 && x<90)
k=2;
if(x>=70 && x<80)
k=3;
if(x>=60 && x<70)
k=4;
if(x<60)
k=5;

swicth(k)
{case 1: printf("\nthe score belong to A !\n");break;
case 2: printf("\nthe score belong to B !\n");break;
case 3: printf("\nthe score belong to c !\n");break;
case 4: printf("\nthe score belong to D !\n");break;
case 5: printf("\nthe score belong to d !\n");break;
default:printf("error!");
}
}/*注意这个括号*/
不知道为什么,这个程序也是有错误的,老是那个错误!说缺少一个小的括号!
我想不明白啊!这个程序不难!算法简单!但是我就是做的不对!请各位高手指点小弟啊!


刚才没有仔细看,13楼说的对, 汉

[此贴子已经被作者于2006-5-14 13:32:42编辑过]


----------------解决方案--------------------------------------------------------

呵呵一时粗心,我也常犯的
你的思路好


----------------解决方案--------------------------------------------------------
这个思路是COPY来的。
惭愧。
----------------解决方案--------------------------------------------------------

呵呵!我非常感谢各位对我的帮助,有时候很奇怪!在编程时,有一些问题自己就是找不出来,可能是因为我编的程序太少的缘故!没有什么经验!呵呵!在一次的谢谢大家哦!


----------------解决方案--------------------------------------------------------
  相关解决方案