3 回答
TA贡献195条经验 获得超115个赞
#include <stdio.h>
int main ()
{
float score;
printf("please enter score:\n");
scanf("%f",&score);
if(score>100||score<0)
{
printf("error!\n please again!\n");
scanf("%f",&score);
}
switch ((int)score/10)
{
case 0:printf("E\n");break ;
case 1:printf("E\n");break ;
case 2:printf("E\n");break ;
case 3:printf("E\n");break ;
case 4:printf("E\n");break ;
case 5:printf("E\n");break ;
case 6:printf("D\n");break ;
case 7:printf("C\n");break ;
case 8:printf("B\n");break ;
case 9:printf("A\n");break ;
case 10:printf("A\n");break ;
}
return 0;
}
输入:
70
输出:
please enter score:
C
你的输入scanf("%f",&score); 有问题,怎么会if
TA贡献143条经验 获得超94个赞
#include <stdio.h> int main () { double score; printf("Please enter score: "); scanf("%lf",&score); if (score > 100 || score < 0) { printf("Error! Please enter again!\n"); scanf("%lf",&score); } switch ((int)score/10) { case 0: printf("E\n"); break ; case 1: printf("E\n"); break ; case 2: printf("E\n"); break ; case 3: printf("E\n"); break ; case 4: printf("E\n"); break ; case 5: printf("E\n"); break ; case 6: printf("D\n"); break ; case 7: printf("C\n"); break ; case 8: printf("B\n"); break ; case 9: printf("A\n"); break ; case 10: printf("A\n"); break ; } return 0; }
格式化输入。
- 3 回答
- 0 关注
- 2314 浏览
添加回答
举报