|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include"stdio.h"
int change(struct student *p, long num, int n, int *i, float *score);
#define NUM 3
struct student
{
char name[20];
long num;
float math, English, computer;
float average;
}students[50];
int main ()
{
int i, n, pos, a[3] = {0};
float score[3] = {0};
char choice;
long num1;
printf("请输入n为学生:");
scanf("%d", &n);
printf("\t\t数学\t英语\t计算机\n\n");
for(i = 0; i < n; i++)
{
printf("请输入第 %d 位同学成绩:", i + 1);
scanf("%f%f%f", &students[i].math, &students[i].English, &students[i].computer);
students[i].average = (students[i].math + students[i].English + students[i].computer) / 3;
}
printf("是否修改成绩(y/n):");
scanf("%c", &choice);
if(choice == 'y')
{
printf("请输入序号修改成绩 1-数学 2-英语 3-计算机 \n\n");
}
while(choice == 'y')
{
printf("请输入要修改的学生学号:\n");
scanf("%d", &num1);
for(i = 0; i < 3; i++)
{
a[i] = i + 1;
printf("请输入修改后的分数:");
scanf("%f", score[i]);
}
printf("是否修改成绩(y/n):");
scanf("%c", &choice);
pos = change(students, num1, n, a, score);
}
//打印
if(pos == -1)
{
printf("NOT FOUND!\n");
}
else
{
printf("After Update, the new information:\n");
printf(" 姓名\t 学号 \t数学\t英语\t计算机\n\n");
printf("%s\t%d\t%f\t%f\t%f\t\n\n", students[pos].name, students[pos].num, students[pos].math, students[pos].English, students[pos].computer);
printf("该生平均分为:%f\n", students[pos].average);
}
return 0;
}
int change(struct student *p, long num, int n, int *i, float *score) //编译器在这儿报错,说参数不兼容,不太明白,求指教。
{
int j, pos;
for(j = 0; j < n; j++)
{
if(p->num == num)
{
break;
}
p++;
}
if(j < n)
{
for(j = 0; j < NUM; j++)
{
switch(i[j])
{
case 1 : p->math = score[j]; break;
case 2 : p->English = score[j]; break;
case 3 : p->computer = score[j]; break;
}
}
pos = j;
}
else
{
pos = -1;
}
return pos;
}
这是源码,问题写在上面,参数不兼容,求指教
你在什么IDE环境下编译的? 我用vs2012没有编译错误。
不过,我建议你将 第二行int change(struct student *p, long num, int n, int *i, float *score);放在struct student结构体声明之后,int main()函数之前试试
|
|