代码如下:
# define _CRT_SECURE_WARINGS
# include<stdio.h>
# include<windows.h>
void test1()
{
unsigned int Score; /*定义为不规则整型,在输入小于0的分数就能跳到提示页面,输入学生分数Score*/
printf("please input a student score:");
scanf("%d", &Score);
printf("This student score belong to ");
switch(Score / 10) /*按10分为一个阶梯把100分分为10段,依次排列*/
{
case 0:
case 1: printf("belong to E\n");break;
case 2:
case 3:
case 4:
case 5: printf("belong to E\n"); break;
case 6: printf("belong to D\n"); break;
case 7: printf("belong to C\n"); break;
case 8: printf("belong to B\n"); break;
case 9: printf("belong to A\n"); break;
case 10:
default: printf("please input a score more then zero and less then one hundred\n"); break;
}
}
test2()
{
int score, grade, sgr; /*定义输入学生分数为SCORE,grade为分级,sgr等于每次键盘输入的分数*/
printf("please input a student score: ");
while(grade)
{
sgr = scanf("%d", &score);
if (sgr)
{
if (score >= 90) printf("the student score belong to A");
else if (score >= 80) printf("the student score belong to B");
else if (score >= 70) printf("the student score belong to C");
else if (score >= 60) printf("the student score belong to D");
else printf("the student score belong to E");
}
else break;
}
return 0;
}
void main()
{
test1();
system("pause");
return EXIT_SUCCESS;
}