给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!");
}
不知道为什么,这个程序也是有错误的,老是那个错误!说缺少一个小的括号!
我想不明白啊!这个程序不难!算法简单!但是我就是做的不对!请各位高手指点小弟啊!
----------------解决方案--------------------------------------------------------
x>=90 x=<90 x>=80 x=<80 x>=70 x=<70
如果给你,你怎么判断啊?
----------------解决方案--------------------------------------------------------
给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) //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;
swicth(k) //switch(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 E !\n");break;
default:printf("error!");
}
不知道为什么,这个程序也是有错误的,老是那个错误!说缺少一个小的括号!
我想不明白啊!这个程序不难!算法简单!但是我就是做的不对!请各位高手指点小弟啊!
[此贴子已经被作者于2006-5-13 19:54:05编辑过]
----------------解决方案--------------------------------------------------------
我真为你们感到伤心,这样的问题自己都搞不定
----------------解决方案--------------------------------------------------------
#include<stdio.h>
int main(void)
{
int x, k;
printf("\nplease input an score:\n");
scanf("%d", &x);
if (x > 90 && x <= 100)
{
k=1;
}
else if(x > 80 && x <= 90)
{
k=2;
}
else if(x > 70 && x <= 80)
{
k=3;
}
else if(x > 60 && x <= 70)
{
k=4;
}
else
{
k=5;
}
switch(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 E !\n");
break;
default:
printf("error!");
}
return 0;
}
----------------解决方案--------------------------------------------------------
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) //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;
swicth(k) //switch(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 E !\n");break;
default:printf("error!");
}
}
应该这样
----------------解决方案--------------------------------------------------------
if(x>=90 && x=<100)也要改为if(x>=90 && x<=100)
才可以
----------------解决方案--------------------------------------------------------
#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!");
}
}
----------------解决方案--------------------------------------------------------
以下是引用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!");
}
}/*注意这个括号*/
不知道为什么,这个程序也是有错误的,老是那个错误!说缺少一个小的括号!
我想不明白啊!这个程序不难!算法简单!但是我就是做的不对!请各位高手指点小弟啊!
[此贴子已经被作者于2006-5-14 12:50:06编辑过]
----------------解决方案--------------------------------------------------------
昏。我刚刚写的时候也少了这个。不过他的程序有算法错误。当然楼上的有改正了!
----------------解决方案--------------------------------------------------------