这个东西怎么错了?求指点,谢谢
// 成绩管理.cpp : Defines the entry point for the console application.//
#include "stdafx.h"
struct Student
{
int number;
char name[10];
float cj[7];
float min,max,ave,total;
}stu[20], temp[20];
int i,j,choice,num;
float deal[8][4];
float sum;
FILE *fp1;
FILE *fp2;
int main(int argc, char* argv[])
{
void student();
void sort();
void subject();
void rank();
printf("********************成绩管理********************\n");
fp1 = fopen("a.txt","r");
printf("输入学生信息:\n");
printf("学号 姓名 \t 高数 \t工图 \t英语 \tC语言 \t 航概 \t 体育 \t 思修 \t\n");
for(i = 1; i <= 20; i++){
fscanf( fp1, "%d%s", &stu[i].number, stu[i].name);
printf( "%d %s \t", stu[i].number, stu[i].name);
for(j = 1; j <= 7; j++){
fscanf( fp1, "%f", &stu[i].cj[j]);
printf( "%5.2f \t", stu[i].cj[j]);
}
printf("\n");
}
fp2 = fopen("b.txt", "w");
fprintf( fp2, "\t\t\t***********成绩单************\t\t\t\n");
fprintf( fp2, "学号 姓名 \t 高数 \t工图 \t英语 \tC语言 \t 航概 \t 体育 \t 思修 \t 最高分\t 最低分\t 平均分\t 总分\t\n");
for( i = 1; i <= 20; i++){
stu[i].max = stu[i].cj[1];
stu[i].min = stu[i].cj[1];
stu[i].total = 0;
for(j = 1; j <= 7; j++){
stu[i].total = stu[i].total+stu[i].cj[j];
if(stu[i].cj[j] > stu[i].max)
stu[i].max = stu[i].cj[j];
if(stu[i].cj[j] < stu[i].min)
stu[i].min = stu[i].cj[j];
}
stu[i].ave = stu[i].total/7;
}
for( i = 1; i <= 20; i++){
fprintf( fp2, "%d\t%s\t", stu[i].number, stu[i].name);
for( j = 1; j <= 7; j++)
fprintf( fp2, "%5.2f\t", stu[i].cj[j]);
fprintf( fp2, "%5.2f\t%5.2f\t%5.2f\t%5.2f\t\n", stu[i].max, stu[i].min, stu[i].ave, stu[i].total);
}
printf( "\t*************************************************************\n" );
printf( "\t\t\t\t学生成绩管理系统\n\t\t\t\t 欢迎使用!\n" );
printf( "\t*************************************************************\n" );
printf( "\n\n\n\t\t\t1--查询某学生成绩\n\t\t\t2--查询某学科成绩\n\t\t\t3--不及格信息统计\n\t\t\t4--成绩排名\n\t\t\t5--退出\n" );
printf( "请选择:\n" );
scanf( "%d", &choice );
while( choice != 5 )
{
switch(choice)
{
case 1: student(); break;
case 2: subject(); break;
case 3: sort(); break;
case 4: rank(); break;
}
printf( "\n请继续输入要进行的操作\n" );
scanf( "%d", &choice );
}
printf( "\t\t欢迎再次使用本系统。\n\n" );
printf( "Hello World!\n" );
return 0;
}
void student()
{
fp2 = fopen( "b.txt", "r" );
printf( "输入学生学号(不超过20):\n" );
scanf( "%d", &num );
for( i = 1; i <= 20; i++ )
if(num == i){
printf( "学号 姓名 \t 高数 \t工图 \t英语 \tC语言 \t 航概 \t 体育 \t 思修 \t 最高分\t 最低分\t 平均分\t 总分\t\n" );
fscanf( fp2, "%d%s", &stu[i].number, stu[i].name );
printf( "%d\t%s\t", stu[i].number, stu[i].name );
for( j = 1; j <= 7; j++ ){
fscanf( fp2, "%5.2f", &stu[i].cj[j] );
printf( "%5.2f\t", stu[i].cj[j] );
}
fscanf( fp2, "%5.2f%5.2f%5.2f%5.2f" , &stu[i].max, &stu[i].min, &stu[i].ave, &stu[i].total );
printf( "%5.2f\t%5.2f\t%5.2f\t%5.2f\t\n", stu[i].max, stu[i].min, stu[i].ave, stu[i].total );
}
};
void rank()
{
fp2 = fopen( "b.txt","r" );
for( i = 1; i < 21; i++ ){//成绩排名
for( j = 1; j < 21-i; j++ )
if( stu[j].total < stu[j+1].total ){
temp[i] = stu[j+1];
stu[j+1] = stu[j];
stu[j] = temp[i];
}
}
printf( "\n\n\n\n总成绩排名:\n" );
printf( "学号 姓名\t高数\t工图\t英语\tC语言\t航概\t体育\t思修\t总分\t\n" );
for( i = 1; i <= 20; i++ ){
fscanf( fp2, "%d%s" , &stu[i].number, stu[i].name );
printf( "%d\t%s\t", stu[i].number, stu[i].name );
for( j = 1; j <= 7 ; j++ ){
fscanf( fp2 , "%5.2f", &stu[i].cj[j] );
printf( "%5.2f\t", stu[i].cj[j] );
}
fscanf( fp2, "%5.2f", &stu[i].total );
printf( "%5.2f\t", stu[i].total );
}
};
void subject()
{
float ave, max, min;
fp2=fopen( "b.txt", "r" );
printf( "\t\t\t1--查询学科总情况\n\t\t\t2--查询某学科情况\n" );
printf( "请选择:\n" );
scanf( "%d", &num );
switch( num ){
case 1:{
printf( "\n\n单科最高分 最低分 平均分:\n" );
for( i = 1; i <= 20; i++ ){
for( j = 1; j <= 7; j++ )
fscanf( fp2, "%5.2f", &stu[i].cj[j] );
}
for( j = 1; j <= 7; j++ ){
deal[j][1] = stu[1].cj[j];//max
deal[j][2] = stu[1].cj[j];//min
for( i = 1; i <= 20; i++ ){
sum = sum + stu[i].cj[j];//总分
if( stu[i].cj[j] > deal[j][1] )
deal[j][1] = stu[i].cj[j];
if( stu[i].cj[j] < deal[j][2] )
deal[j][2] = stu[i].cj[j];
}
deal[j][3] = sum/20;
sum = 0;//平均分
}
printf( "\t高数\t工图\t英语\tC语言\t航概\t体育\t思修\t\n" );
printf( "最高分\n最低分\n平均分\n" );
for( j = 1; j <= 3; j++ )
{
printf( "\n" );
for( i = 1; i <= 7; i++ )
{
printf( "\t%5.2f", deal[i][j] );
}
printf( "\n" );
}
}
break;
case 2:{
printf( "\t\t\t1--高数\n\t\t\t2--工图\n\t\t\t3--英语\n\t\t\t4--C语言\n\t\t\t5--航概\n\t\t\t6--体育\n\t\t\t7--思修\n" );
printf( "请选择:\n" );
scanf( "%d", &choice );
for( j = 1; j <= 7; j++ ){
max = stu[1].cj[j];
min = stu[1].cj[j];
if( choice == j ){
for( i = 1; i <= 20; i++ )
sum = sum + stu[i].cj[j];
if( stu[i].cj[j] > max )
max = stu[i].cj[j];
if( stu[i].cj[j] < min )
min = stu[i].cj[j];
ave = sum/20;
}
}
printf( "\t\t最高分\t最低分\t平均分\t\n" );
printf( "\t\t%5.2f\t%5.2f\t%5.2f\t", max, min, ave );
}
}
};
void sort()
{
fp2 = fopen( "b.txt", "r" );
int flag[7], amount;
printf( "\t\t\t1--不及格人数统计\n\t\t\t2--不及格门数统计\n" );
printf( "请选择:\n" );
scanf( "%d" , &num );
switch( num )
{
case 1:{
for( j = 1; j <= 7; j++ ){
flag[j] = 0;
for( i = 1; i <= 20; i++ ){
if( stu[i].cj[j] < 60 )
flag[j]++;
}
}
printf( "\t高数\t工图\t英语\tC语言\t航概\t体育\t思修\t\n" );
printf( "人数\t" );
for( j = 1; j <= 7; j++ )
printf( "%d\t", flag[j] );
printf( "\n" );
break;
}
case 2:{
amount = 0;
for(i = 1; i <= 20; i++ ){
for( j = 1; j <= 7; j++ )
if( stu[i].cj[j] < 60 )
amount++;
}
printf( "不及格总门数: " );
printf( "%d\n", amount );
break;
}
}
};