关于switch的语句,不知道问题出哪了,麻烦高手看看,谢谢。
(1)//当我把scanf_s("%d",&score);改成scanf_s("%f",&score);保留int score=0;时,float无论我输入什么输出的都是Please enter the score between 0 to 100这是输出结果
Please enter the score:99
Please enter the score between 0 to 100
(2)//当我把scanf_s("%f",&score);改成scanf_s("%d",&score),并且把int score=0改成float score=0;时,无论我怎么输入,它输出都是显示Your grade is: E
这是输出结果
Please enter the score:89
Your grade is:E
Please enter the score:123
Your grade is:E
//只有在float score=0; 和scanf_s("%f",&score)的情况下才能正确输出结果, 所以我想知道出现上面两种情况的原因是什么。
#include<stdio.h>
int main(void)
{
int score=0;
char ch=0;
printf("Please enter the score:");
scanf_s("%f",&score);
while (score < 0 || score>100)
{
printf("Please enter the score between 0 to 100:");
scanf_s("%f", &score);
}
switch ((int)score/10)
{
case 10:
case 9:ch = 'A'; break;
case 8:ch = 'B'; break;
case 7:ch = 'C'; break;
case 6:ch = 'D'; break;
case 5:
case 4:
case 3:
case 2:
case 1:
case 0:ch = 'E';
default:break;
}
printf("Your grade is:%c\n", ch);
return 0;
}