利用if-else语句编程,根据输入的百分制成绩score,转换成相应的五分制成绩grade后输出 老是有错 求指导啊
main()
{
float score,grade;
char A,B,C,D,E;
printf("Input score:");
scanf("%f",&score);
if (score>=90&&score<=100) grade=A;
{
printf("%c",grade);
}
else if (score>=80&&score<90) grade=B;
{
printf("%c",grade);
}
else if(score>=70&&score<80) grade=C;
{
printf("%c",grade);
}
else if(score>=60&&score<70) grade=D;
{
printf("%c",grade);
}
else if(score>=0&&score<60) grade=E;
{
printf("%c",grade);
}
return 0;
}
老是提示有错求大神指导 明天交作业了啊啊啊!!!!!!! 展开
#include<stdio.h>
void main()
{
float score;
char a='A',b='B',c='C',d='D',e='E',grade;
printf("Input score:\n");
scanf("%f",&score);
if (score>=90&&score<=100)
printf("%c\n",grade=a);
else if (score>=80&&score<90)
printf("%c\n",grade=b);
else if(score>=70&&score<80)
printf("%c\n",grade=c);
else if(score>=60&&score<70)
printf("%c\n",grade=d);
else if(score>=0&&score<60)
printf("%c\n",grade=e);
else if(score>100||score<0)
printf("成绩出错\n");
}
字符常量只能用单引号括起来,改了就好了grade='A'等是可以省的;
如果成绩输错可以显示,保证程序的完备性;
希望可以帮到你!
#include<stdio.h>
main()
{
float score;
char grade;
printf("Input score:");
scanf("%f",&score);
if (score>=90&&score<=100) grade='A';
else if (score>=80&&score<90) grade='B';
else if(score>=70&&score<80) grade='C';
else if(score>=60&&score<70) grade='D';
else if(score>=0&&score<60) grade='E';
else grade='F';
printf("%c\n",grade);
return 0;
}
然后 将float grade 声明为字符型 : char grade 这样就行了
grade = ‘A’;