C语言!!!!急!!!
#include<string.h>
#include<stdlib.h>
#define N 100
struct score
{
float math;
float english;
float computer;
};
struct student
{
int number;
char name[20];
struct score sco;
float average;
};
struct student stu[N];
float input_score(int);//计算学生平均成绩
void print_student2(void);//显示表头
void print_student3(int);//显示学生信息
void print_student1(int);//显示全部学生资料
void print_student1(int a)//显示全部学生资料
{
printf("本班所有学生具体信息如下\n");
print_student2();
for(int i=0;i<a;i++)
{
print_student3(i);
}
}
void print_student3(int a)//显示学生信息
{
printf("%8d%12s%14.2f%14.2f%14.2f%14.2f\n",stu[a].number,stu[a].name,stu[a].sco.math,stu[a].sco.english,stu[a].sco.computer,stu[a].average);
}
void print_student2(void)//显示表头
{
printf(" 学号 姓名 数学成绩 英语成绩 计算机成绩 平均成绩\n");
}
void input_student1(int a)//输入学生信息
{
printf("学号:");
scanf("%d",&stu[a].number);
getchar();
printf("姓名:");
gets(stu[a].name);
printf("数学成绩:");
scanf("%f",&stu[a].sco.math);
printf("英语成绩:");
scanf("%f",&stu[a].sco.english);
printf("计算机成绩:");
scanf("%f",&stu[a].sco.computer);
}
float input_score(int a)//计算学生平均成绩
{
return (stu[a].sco.math+stu[a].sco.english+stu[a].sco.computer)/3;
}
void main()
{
struct student stu[N];
input_score(student);
print_student2(student);
print_student3(student);
print_student1(student);
print_student1(student);
}
错误
Cpp3.cpp
C:\Users\asus\Desktop\Cpp3.cpp(62) : error C2275: 'student' : illegal use of this type as an expression
C:\Users\asus\Desktop\Cpp3.cpp(12) : see declaration of 'student'
C:\Users\asus\Desktop\Cpp3.cpp(63) : error C2275: 'student' : illegal use of this type as an expression
C:\Users\asus\Desktop\Cpp3.cpp(12) : see declaration of 'student'
C:\Users\asus\Desktop\Cpp3.cpp(64) : error C2275: 'student' : illegal use of this type as an expression
C:\Users\asus\Desktop\Cpp3.cpp(12) : see declaration of 'student'
C:\Users\asus\Desktop\Cpp3.cpp(65) : error C2275: 'student' : illegal use of this type as an expression
C:\Users\asus\Desktop\Cpp3.cpp(12) : see declaration of 'student'
C:\Users\asus\Desktop\Cpp3.cpp(66) : error C2275: 'student' : illegal use of this type as an expression
C:\Users\asus\Desktop\Cpp3.cpp(12) : see declaration of 'student'
Error executing cl.exe.
Cpp3.exe - 5 error(s), 0 warning(s)
帮忙修改并能运行出来!!万分感谢!! 展开
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define N 3
struct score
{
float math;
float english;
float computer;
};
struct student
{
int number;
char name[20];
struct score sco;
float average;
};
struct student stu[N];
float input_score(int);//计算学生平均成绩
void print_student2(void);//显示表头
void print_student3(int);//显示学生信息
void print_student1(int);//显示全部学生资料
void print_student1(int a)//显示全部学生资料
{
printf("本班所有学生具体信息如下\n");
print_student2();
for(int i=0;i<a;i++)
{
print_student3(i);
}
}
void print_student3(int a)//显示学生信息
{
printf("%8d%12s%14.2f%14.2f%14.2f%14.2f\n",stu[a].number,stu[a].name,stu[a].sco.math,stu[a].sco.english,stu[a].sco.computer,stu[a].average);
}
void print_student2(void)//显示表头
{
printf(" 学号 姓名 数学成绩 英语成绩 计算机成绩 平均成绩\n");
}
void input_student1(int a)//输入学生信息
{
printf("学号:");
scanf("%d",&stu[a].number);
getchar();
printf("姓名:");
gets(stu[a].name);
printf("数学成绩:");
scanf("%f",&stu[a].sco.math);
printf("英语成绩:");
scanf("%f",&stu[a].sco.english);
printf("计算机成绩:");
scanf("%f",&stu[a].sco.computer);
}
float input_score(int a)//计算学生平均成绩
{
return (stu[a].sco.math+stu[a].sco.english+stu[a].sco.computer)/3;
}
int main()
{
input_student1(1);
input_score(1);
print_student2();
print_student3(1);
print_student1(1);
print_student1(1);
}
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define N 100
struct score {
float math;
float english;
float computer;
};
struct student {
int number;
char name[20];
struct score sco;
float average;
};
struct student stu[N];
float input_score(int); //计算学生平均成绩
void print_student2(void); //显示表头
void print_student3(int); //显示学生信息
void print_student1(int); //显示全部学生资料
void print_student1(int a) //显示全部学生资料
{
printf("本班所有学生具体信息如下\n");
print_student2();
for (int i = 0; i < a; i++) {
print_student3(i);
}
}
void print_student3(int a) //显示学生信息
{
printf("%8d%12s%14.2f%14.2f%14.2f%14.2f\n", stu[a].number,
stu[a].name, stu[a].sco.math, stu[a].sco.english,
stu[a].sco.computer, stu[a].average);
}
void print_student2(void) //显示表头
{
printf(" 学号 姓名 数学成绩 英语成绩 计算机成绩 平均成绩\n");
}
void input_student1(int a) //输入学生信息
{
printf("学号:");
scanf("%d", &stu[a].number);
printf("姓名:");
scanf("%s", stu[a].name);
printf("数学成绩:");
scanf("%f", &stu[a].sco.math);
printf("英语成绩:");
scanf("%f", &stu[a].sco.english);
printf("计算机成绩:");
scanf("%f", &stu[a].sco.computer);
}
float input_score(int a) //计算学生平均成绩
{
stu[a].average = (stu[a].sco.math + stu[a].sco.english + stu[a].sco.computer) / 3;
return stu[a].average;
}
void main(void)
{
input_student1(0);
input_score(0);
print_student2();
print_student3(0);
}