代码我已经调试过了,可以直接用!
#include
int main(){
double score;
printf("请输入你的成绩:");
scanf("%lf",&score);
switch((int)(score/10)){
case 10:
case 9:
case 8:printf("A\n");break;
case 7:printf("B\n");break;
case 6:printf("C\n");break;
case 5:
case 4:
case 3:
case 2:
case 1:printf("D\n");break;
default:printf("error\n");
}
return 0;
}
#include
void main()
{
int grade,n;
printf("请输入分数:\n");
scanf("%d",&grade);
if (grade>=85&&grade<=100)
n=1;
else if(grade>=70&&grade<=84)
n=2;
else if (grade>=60&&grade<=69)
n=3;
else n=4;
switch(n)
{
case 1:printf("A\n");break;//85~100
case 2:printf("B\n");break;
case 3:printf("C\n");break;
case 4:printf("D\n");break;
defeat:printf("input error\n");
}
}
winxp sp3 VC6环境下测试能运行,不过我写的不是最简单的。
最简单最笨的,把case 100,case 99,...case 1,全列出来
int score;
//...
switch(score)
{
case 100:
case 99:
//省略case 98: - case 86:
case 85:printf("A");break;
case 84:
case 83:
//省略case 82: - case 71:
case 70:printf("B");break;
//...
}
#include "stdio.h"
void main()
{
int grade;
printf("please input a number:");
scanf("%d",&grade);
switch(grade)
{
case'A':printf("85~100\n");
case'B':printf("70~84\n");
case'C':printf("60~69\n");
case'D':printf("<60\n");
default:printf("error");
}
}
#include "stdio.h"
void main()
{
char grade;
printf("please input a number:");
scanf("%c",&grade);
switch(grade)
{
case'A':printf("85~100\n");break;
case'B':printf("70~84\n");break;
case'C':printf("60~69\n");break;
case'D':printf("<60\n");break;
default:printf("error");break;
}
}