如何用switch实现:百分制,输出成绩分A、B、C、D、E。90分以上为A,80~89为B,70~79分为C,60~69分为D 5
展开全部
假设百分制的成绩 0--60为 E其他的依次类推 可编程如下 :
main()
{float c;int s;
char grade;
scanf("%f,%d",&c,&s);
if(c>100) s=10;
else s=(int)c/10;
switch (c)
{case 0:
case 1:
case 2:
case 3:
case 4:
case 5:grade'E';break;
case 6:grade'D';break;
case 7:grade'C';break;
case 8:grade'B';break;
case 9;
case 10:grade'A';break;
}
printf("%c",grade);
}
可能有些语法或输入的错误 运行时检查就能消除了
main()
{float c;int s;
char grade;
scanf("%f,%d",&c,&s);
if(c>100) s=10;
else s=(int)c/10;
switch (c)
{case 0:
case 1:
case 2:
case 3:
case 4:
case 5:grade'E';break;
case 6:grade'D';break;
case 7:grade'C';break;
case 8:grade'B';break;
case 9;
case 10:grade'A';break;
}
printf("%c",grade);
}
可能有些语法或输入的错误 运行时检查就能消除了
展开全部
我的程序源代码,可以直接到C++中运行。
#include <iostream.h>
void main()
{
int score;
loop: cout<<"请输入分数:\n";
cin>>score;
switch(score/10)
{
case 10:
case 9:cout<<"A\n";break;
case 8:cout<<"B\n";break;
case 7:cout<<"C\n";break;
case 6:cout<<"D\n";break;
default:cout<<"E\n";
}
goto loop;
}
#include <iostream.h>
void main()
{
int score;
loop: cout<<"请输入分数:\n";
cin>>score;
switch(score/10)
{
case 10:
case 9:cout<<"A\n";break;
case 8:cout<<"B\n";break;
case 7:cout<<"C\n";break;
case 6:cout<<"D\n";break;
default:cout<<"E\n";
}
goto loop;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include <stdio.h>
int main(void)
{
int score;
int grade;
char result;
scanf("%d",&score);
grade = score / 10;
switch(grade)
{
case 10:
case 9: result = 'A';
break;
case 8: result = 'B';
break;
case 7: result = 'C';
break;
case 6: result = 'D';
break;
default: result = 'E';
break;
}
printf("%c\n",result);
return 0;
}
int main(void)
{
int score;
int grade;
char result;
scanf("%d",&score);
grade = score / 10;
switch(grade)
{
case 10:
case 9: result = 'A';
break;
case 8: result = 'B';
break;
case 7: result = 'C';
break;
case 6: result = 'D';
break;
default: result = 'E';
break;
}
printf("%c\n",result);
return 0;
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询