C语言代码求助
#pragmawarning(disable:4996)#include<stdio.h>#include<stdlib.h>intcount;structStudent...
#pragma warning(disable : 4996)
#include<stdio.h>
#include<stdlib.h>
int count;
struct Student
{
char name[30];
int ID;
float Chinese;
float Math;
float English;
struct Student *next;
};
struct Student* Create(int Long)
{
struct Student *head = NULL;
struct Student *new;
struct Student *end;
new = end = (struct Student*)malloc(sizeof(struct Student));
count = 0;
printf("请输入第%d个同学的名字:\n", (count + 1));
scanf("%s", new->name);
printf("请输入第%d个同学的学号:\n", (count + 1));
scanf("%d", &new->ID);
printf("请输入第%d个同学的语文成绩:\n", (count + 1));
scanf("%f", &new->Chinese);
printf("请输入第%d个同学的数学成绩:\n", (count + 1));
scanf("%f", &new->Math);
printf("请输入第%d个同学的英语成绩:\n", (count + 1));
scanf("%f", &new->English);
while (1)
{
count++;
if (count = 1)
{
new->next = NULL;
head = new;
end = head;
}
else
{
new->next = NULL;
end->next = new;
end = new;
}
if (count = Long)
goto a;
new = (struct Student*)malloc(sizeof(struct Student));
printf("请输入第%d个同学的名字:\n", (count + 1));
scanf("%s", new->name);
printf("请输入第%d个同学的学号:\n", (count + 1));
scanf("%d", &new->ID);
printf("请输入第%d个同学的语文成绩:\n", (count + 1));
scanf("%f", &new->Chinese);
printf("请输入第%d个同学的数学成绩:\n", (count + 1));
scanf("%f", &new->Math);
printf("请输入第%d个同学的英语成绩:\n", (count + 1));
scanf("%f", &new->English);
}
a:
free(new);
return head;
}
int main()
{
struct Student *head;
int Long, i, b;
b = 0;
printf("请输入要记录学生的数量:\n");
scanf("%d", &Long);
head = Create(Long);
printf("成绩少于60分的同学:\n");
for (i = 1; i <= count; i++)
{
if ((head->Chinese < 60) || (head->Math < 60) || (head->English < 60))
{
printf("名字:%s\n", head->name);
printf("学号:%d\n", head->ID);
printf("语文成绩:%f\n", head->Chinese);
printf("数学成绩:%f\n", head->Math);
printf("英语成绩:%f\n", head->English);
printf("======================================\n");
b++;
}
head = head->next;
}
if (b = 0)
printf("没有人不及格!\n");
return 0;
}
================
如代码,我原本想实现的是通过链表来储存学生数据,并输出不及格的同学信息,但不知为何总是有错,求各位大神看一看 展开
#include<stdio.h>
#include<stdlib.h>
int count;
struct Student
{
char name[30];
int ID;
float Chinese;
float Math;
float English;
struct Student *next;
};
struct Student* Create(int Long)
{
struct Student *head = NULL;
struct Student *new;
struct Student *end;
new = end = (struct Student*)malloc(sizeof(struct Student));
count = 0;
printf("请输入第%d个同学的名字:\n", (count + 1));
scanf("%s", new->name);
printf("请输入第%d个同学的学号:\n", (count + 1));
scanf("%d", &new->ID);
printf("请输入第%d个同学的语文成绩:\n", (count + 1));
scanf("%f", &new->Chinese);
printf("请输入第%d个同学的数学成绩:\n", (count + 1));
scanf("%f", &new->Math);
printf("请输入第%d个同学的英语成绩:\n", (count + 1));
scanf("%f", &new->English);
while (1)
{
count++;
if (count = 1)
{
new->next = NULL;
head = new;
end = head;
}
else
{
new->next = NULL;
end->next = new;
end = new;
}
if (count = Long)
goto a;
new = (struct Student*)malloc(sizeof(struct Student));
printf("请输入第%d个同学的名字:\n", (count + 1));
scanf("%s", new->name);
printf("请输入第%d个同学的学号:\n", (count + 1));
scanf("%d", &new->ID);
printf("请输入第%d个同学的语文成绩:\n", (count + 1));
scanf("%f", &new->Chinese);
printf("请输入第%d个同学的数学成绩:\n", (count + 1));
scanf("%f", &new->Math);
printf("请输入第%d个同学的英语成绩:\n", (count + 1));
scanf("%f", &new->English);
}
a:
free(new);
return head;
}
int main()
{
struct Student *head;
int Long, i, b;
b = 0;
printf("请输入要记录学生的数量:\n");
scanf("%d", &Long);
head = Create(Long);
printf("成绩少于60分的同学:\n");
for (i = 1; i <= count; i++)
{
if ((head->Chinese < 60) || (head->Math < 60) || (head->English < 60))
{
printf("名字:%s\n", head->name);
printf("学号:%d\n", head->ID);
printf("语文成绩:%f\n", head->Chinese);
printf("数学成绩:%f\n", head->Math);
printf("英语成绩:%f\n", head->English);
printf("======================================\n");
b++;
}
head = head->next;
}
if (b = 0)
printf("没有人不及格!\n");
return 0;
}
================
如代码,我原本想实现的是通过链表来储存学生数据,并输出不及格的同学信息,但不知为何总是有错,求各位大神看一看 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询