int ModifyList() { int i, item; long int a; printf("输入要修改学生的学号:\n"); scanf("%ld", &a); for (i = 1; i <= M; i++) { if (stu[i].num == a) { printf(" 1.大学英语成绩 \n"); printf(" 2.数据结构成绩 \n"); printf(" 0.退出 \n"); while (1) { printf("Please choose:"); scanf("%d", &item); switch (item) { case 1: printf("请输入新成绩:\n"); scanf("%f", &stu[i].english); break; case 2: printf("请输入新成绩:\n"); scanf("%f", &stu[i].computer); break; default: printf("Input error!\n"); } if (item == 0) break; } } } }
时间: 2024-01-17 21:05:15 浏览: 31
这段代码仍然存在一些问题。主要包括以下几点:
1. 函数没有返回值。如果你希望函数返回一个值,需要在函数定义时指定返回值类型,并在函数体中使用`return`语句返回一个值。
2. 学生信息结构体没有被定义。在这段代码中,我们看不到`struct student`的定义。因此,需要在代码开头定义一个`struct student`结构体。
3. 缺少头文件。这段代码中使用了`printf`和`scanf`函数,但是没有包含相应的头文件。需要在代码开头添加`#include <stdio.h>`。
下面是修改后的代码:
```
#include <stdio.h>
struct student {
long int num;
float english;
float computer;
};
int ModifyList() {
int i, item;
long int a;
printf("输入要修改学生的学号:\n");
scanf("%ld", &a);
for (i = 1; i <= M; i++) {
if (stu[i].num == a) {
printf(" 1.大学英语成绩 \n");
printf(" 2.数据结构成绩 \n");
printf(" 0.退出 \n");
while (1) {
printf("Please choose:");
scanf("%d", &item);
switch (item) {
case 1:
printf("请输入新成绩:\n");
scanf("%f", &stu[i].english);
break;
case 2:
printf("请输入新成绩:\n");
scanf("%f", &stu[i].computer);
break;
default:
printf("Input error!\n");
}
if (item == 0)
break;
}
}
}
return 0;
}
```
相关推荐
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)