问题:
1.输入时有时会直接跳出
2.在进行第一个函数时,会输出各种奇怪的数值,负的
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 30
int input(int id[],int score[N][5],int n)
{
for(int i=0;i<n;i++)
{
scanf("%d %d %d %d %d %d",&id[i],&score[i][0],&score[i][1],&score[i][2],&score[i][3],&score[i][4]);
}
}
int AverCourse(int *pscore, int n, int m)//求第m门课程的平均分
{
int sum=0;
for(int i=0;i<n;i++)
{
sum=sum+(*(pscore+i)+m);
}
printf("aver=%d\n",sum/n);
}
void FindNoPassStu(int(*pscore)[5], int *num, int n, int *nopassnum)//找出有2门及2门以上不及格的学生的学号信息
{
for(int i=0;i<n;i++)
{
int a;
for(int j=0;j<5;j++)
{
if(*(*(pscore+i)+j) < 60)
{
a++;
}
if(a>=2)
{
nopassnum=num+i;
}
return nopassnum;
}
}
}
void FindGoodStu(int *pscore ,int *num, int n, int *goodnum)//出均分大于等于90 分的学生的学号信息
{
for(int i=0;i<n;i++)
{
int sum=0;
for(int j=0;j<5;j++)
{
sum=sum+(*(pscore+i)+j);
}
if((sum/5)>=90)
{
goodnum=num+i;
}
return goodnum;
}
}
int main()
{
int n;
scanf("%d",&n);
int id[]={0};
int score[][5]={0};
input(id,score,n);
getchar();
int a;
while(1)
{
system("cls");
printf("1.Find the average score of the mth course\n");
printf("2.Find out the student ID information of students who have failed 2 or more courses\n");
printf("3.Find out the student ID information for students with a point average of 90 or greater\n");
printf("0.Exit the system\n");
printf("Please enter your choice:\n");
scanf("%d", &a);
switch(a)
{
case 1:
system("cls");
int m;
printf("Which course would you like to calculate the average value for:");
scanf("%d",&m);
AverCourse(score,n,m);
break;
case 2:
system("cls");
int *nopassnum=NULL;
printf("Those who fail two or more courses are:\n");
FindNoPassStu(score,id,n,nopassnum);
break;
case 3:
system("cls");
int *goodnum=NULL;
printf("The student ID information for students with an average score of 90 or higher is:\n");
FindGoodStu(score,id,n,goodnum);
break;
case 0:
system("cls");
printf("Exit the system\n");
return 0;
default:
printf("Input error!\n");
}
if(a==1||a==2||a==3||a==0)
{
int x;
printf("返回主菜单请按0,退出程序 1:");
scanf("%d",&x);
if(x==0) continue;
else if(x==1) return 0;
}
}
return 0;
}
不知道你这个问题是否已经解决, 如果还没有解决的话:
int id[]={0};
int score[][5]={0};
这里没有正确分配空间,导致下面都是越界