VC编一道简单程序,帮忙看看我哪儿错了
从键盘输入一个一百分制成绩,如果不在0~100范围内,则要求重新输入数据,直到输入的数据在0~100范围内。将输入的数据转换成等级‘A’,‘B’,‘C’,‘D’,‘E’。...
从键盘输入一个一百分制成绩,如果不在0~100范围内,则要求重新输入数据,直到输入的数据在0~100范围内。将输入的数据转换成等级‘A’,‘B’,‘C’,‘D’,‘E’。90分以上为‘A’,80~89分为‘B’,70~79分为‘C’,60~69分为‘D’,60分以下为‘E’,要求使用switch、case、default语句,结果赋值给变量grade,并将变量grade的值输出到屏幕上。
#include<stdio.h>
int main (void)
{
float ss;
char grase;
do
{
printf("please input the score(0-100): ");
scanf("%.f", &ss);
}
while (ss < 0 || ss > 100);
switch (ss)
{
case 100:
case 90:
grade = 'A';
break;
case 80:
grade = 'B';
break;
case 70:
grade = 'C';
break;
case 60:
grade = 'D';
break;
default:
grade = 'E';
}
printf("\nscore=%.f,grade=%c", ss, grade);
return 0;
} 展开
#include<stdio.h>
int main (void)
{
float ss;
char grase;
do
{
printf("please input the score(0-100): ");
scanf("%.f", &ss);
}
while (ss < 0 || ss > 100);
switch (ss)
{
case 100:
case 90:
grade = 'A';
break;
case 80:
grade = 'B';
break;
case 70:
grade = 'C';
break;
case 60:
grade = 'D';
break;
default:
grade = 'E';
}
printf("\nscore=%.f,grade=%c", ss, grade);
return 0;
} 展开
3个回答
展开全部
#include<stdio.h>
int main (void)
{
float ss;
char grase;
int nStage = 0;
do
{
printf("please input the score(0-100): ");
scanf("%.f", &ss);
}
while (ss < 0 || ss > 100);
nStage = ss / 10;
switch (nStage)
{
case 10:
case 9:
grade = 'A';
break;
case 8:
grade = 'B';
break;
case 7:
grade = 'C';
break;
case 6:
grade = 'D';
break;
default:
grade = 'E';
}
printf("\nscore=%.f,grade=%c", ss, grade);
return 0;
}
int main (void)
{
float ss;
char grase;
int nStage = 0;
do
{
printf("please input the score(0-100): ");
scanf("%.f", &ss);
}
while (ss < 0 || ss > 100);
nStage = ss / 10;
switch (nStage)
{
case 10:
case 9:
grade = 'A';
break;
case 8:
grade = 'B';
break;
case 7:
grade = 'C';
break;
case 6:
grade = 'D';
break;
default:
grade = 'E';
}
printf("\nscore=%.f,grade=%c", ss, grade);
return 0;
}
追问
为什么要除10啊?
追答
不然你如何处理85分呢,85/10=8.5转化为int型不就是8了么,为了处理一定的范围。
以此类推,9处理 90 ——99分的范围是不是足够了,8处理80——89分是不是足够了?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询