c语言:编写程序,输入是个学生的学号、姓名成绩,输出学生成绩等级和不及格人数。
定义调用set_grade()设置等级A85100C6069B7084D059#include<stdio.h>#include<string.h>structstude...
定义调用set_grade()设置等级A85 100 C60 69 B70 84 D 0 59
#include<stdio.h>
#include<string.h>
struct student{
int num;
char name[10];
int score;
char grade[1];
};
char set_grade(int score);
int main()
{
int i,count=0,score;
struct student students[10];
for(i=0;i<10;i++){
printf("Input the student's num:");
scanf("%d",&students[i].num);
printf("Input the student's name:");
scanf("%s",students[i].name);
printf("Input the student's score:");
scanf("%d",&students[i].score);
strcpy(students[i].grade,"set_grade(score)");
if(students[i].grade-"D"==0)
count++;
}
printf("num\t name\t score\t grade\n");
for(i=0;i<10;i++)
printf("%d\t%s\t%d\t%s\n",students[i].num,students[i].name,students[i].score,students[i].grade);
printf("不及格人数:%d\n",count);
return 0;
}
char set_grade(int score)
{
if(score>=85&&score<=100)
return 'A';
else if(score>=70&&score<=84)
return 'B';
else if(score>=60&&score<=69)
return 'C';
else
return 'D';
} 展开
#include<stdio.h>
#include<string.h>
struct student{
int num;
char name[10];
int score;
char grade[1];
};
char set_grade(int score);
int main()
{
int i,count=0,score;
struct student students[10];
for(i=0;i<10;i++){
printf("Input the student's num:");
scanf("%d",&students[i].num);
printf("Input the student's name:");
scanf("%s",students[i].name);
printf("Input the student's score:");
scanf("%d",&students[i].score);
strcpy(students[i].grade,"set_grade(score)");
if(students[i].grade-"D"==0)
count++;
}
printf("num\t name\t score\t grade\n");
for(i=0;i<10;i++)
printf("%d\t%s\t%d\t%s\n",students[i].num,students[i].name,students[i].score,students[i].grade);
printf("不及格人数:%d\n",count);
return 0;
}
char set_grade(int score)
{
if(score>=85&&score<=100)
return 'A';
else if(score>=70&&score<=84)
return 'B';
else if(score>=60&&score<=69)
return 'C';
else
return 'D';
} 展开
1个回答
展开全部
strcpy(students[i].grade,"set_grade(score)"); => students[i].grade=set_grade(score);
students[i].grade-"D"==0 => students[i].grade-'D'==0
students[i].grade-"D"==0 => students[i].grade-'D'==0
更多追问追答
追问
改成这样有错误啊
cannot convert from 'char' to 'char [1]'
追答
char grade[1]; =》 char grade;
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询