请问这个第六步运行怎么该改,显示expected primary-expression before‘【’token错误
#include
#include
#include
#define LEN sizeof(struct Student)
struct Student{
char number[20]; //学号
char name[10]; //姓名
int Chinese; //语文成绩
struct Student* next; //指向下一个数据的指针
};
struct Student* head = NULL;
struct Student* end = NULL;
void Menu(){
void Menu();
void Add();
void View();
void Delete();
void Repair();
void ViewAll();
system("cls");
printf("1、学生信息录入\n");
printf("2、学生单个成绩查询\n");
printf("3、查询全部学生成绩\n");
printf("4、修改学生信息\n");
printf("5、删除学生信息\n");
printf("6、显示出某个分数段学生的信息");
printf("7、退出系统\n");
int choice;
printf("请选择要使用的功能:\n");
loop:
scanf("%d",&choice);
switch (choice) {
case 1:
Add();
Menu();
case 2:
View();
Menu();
case 3:
ViewAll();
Menu();
case 4:
Repair();
Menu();
case 5:
Delete();
Menu();
case 6:
exit(0);
default:
printf("输入有误,请重新选择:");
goto loop;
}
}
void Add(){
system("cls");
int count;
printf("请输入要录入信息的个数:");
scanf("%d",&count);
struct Student *s1,*s2,*temp;
s1=s2=(struct Student*)malloc(LEN);
if(head==NULL){
head = s1;
}else{
end->next = s1 ;
}
int i = 1;
while(count>0){
printf("请输入第%d位学生信息:\n",i++);
printf("学号:\n");
scanf("%s",&s1->number);
printf("姓名:\n");
scanf("%s",&s1->name);
printf("c语言成绩:\n");
scanf("%d",&s1->Chinese);
count--;
s2->next=s1;
s2=s1;
s1=(struct Student*)malloc(LEN);
printf("添加成功!\n");
system("pause");
system("cls");
}
s2->next= NULL;
end = s2;
printf("全部添加成功!\n");
system("pause");
}
void View(){
system("cls");
struct Student *VS;
int choice;
printf("请输入查询方式:\n");
printf("1、按学号查询\n");
printf("2、按姓名查询\n");
loop:
scanf("%d",&choice);
if (choice != 1 && choice != 2) {
printf("输入有误,请重新选择:");
goto loop;
}
char str[20];
if (choice == 1) {
printf("请输入要查询信息的学生学号:\n");
scanf("%s", str);
for(VS=head;VS!=NULL;VS=VS->next){
if(strcmp(VS->number,str)==0){
printf("成功找到!\n");
printf("学号:%s\t姓名:%s\n",VS->number,VS->name);
printf("c语言:%d\n",VS->Chinese);
system("pause");
return;
}
}
} else if (choice == 2) {
printf("请输入要查询信息的学生姓名:\n");
scanf("%s", str);
for(VS=head;VS!=NULL;VS=VS->next){
if(strcmp(VS->name,str)==0){
printf("成功找到!\n");
printf("学号:%s\t姓名:%s\n",VS->number,VS->name);
printf("c语言:%d\n",VS->Chinese);
system("pause");
return;
}
}
}
printf("不好意思,未找到!\n");
system("pause");
}
void ViewAll(){
system("cls");
struct Student *VA;
if(head!=NULL){
printf("所有学生成绩如下:\n");
for(VA=head;VA!=NULL;){
printf("学号:%s\t姓名:%s\tc语言:%d\n",VA->number,VA->name,VA->Chinese);
VA=VA->next;
}
}else{
printf("该系统中还未录入信息");
}
system("pause");
}
void Repair(){
system("cls");
struct Student *RS;
int choice;
printf("请输入查询方式:\n");
printf("1.按照查询学号方式修改\n");
printf("2.按照查询姓名方式修改\n");
loop:
scanf("%d",&choice);
if (choice !=1&&choice !=2) {
printf("输入有误,请重新输入");
goto loop;
}
char str[20];
if (choice == 1) {
printf("请输入学号:\n");
scanf("%s",&str);
for(RS=head;RS!=NULL;RS=RS->next){
if(strcmp(RS->number,str)==0){
printf("成功找到该学生");
printf("学号:%s\t姓名:%s\n",RS->number,RS->name);
printf("c语言:%d\n",RS->Chinese);
printf("c语言成绩:\n");
scanf("%d",&RS->Chinese);
printf("修改成功");
system("pause");
return;
}
}
}
else if (choice ==2) {
printf("请输入姓名:\n");
scanf("%s",&str);
for(RS=head;RS!=NULL;RS=RS->next) {
if(strcmp(RS->name,str)==0) {
printf("成功找到该学生");
printf("学号:%s\t姓名:%s\n",RS->number,RS->name);
printf("c语言:%d\n",RS->Chinese);
printf("c语言成绩:\n");
scanf("%d",&RS->Chinese);
printf("修改成功");
system("pause");
return;
}
}
}
else {
printf("输入信息有误,未查询到 \n");
system("pause");
}
}
void Delete(){
system("cls");
int flag =1;
while(flag){
printf("请输入要删除的学生学号:");
char num[10];
scanf("%s",&num);
struct Student * DS,*temp;
for(DS=head;DS!=NULL;){
if(strcmp(DS->number,num)==0){
if(DS==head){
head = DS->next;
flag = 0;
printf("删除成功!\n");
system("pause");
}else{
flag = 0;
printf("删除成功!\n");
temp->next= DS->next;
free(DS);
system("pause");
}
}
temp = DS;
DS=DS->next;
}
if(flag){
printf("未找到该学生学号!\n");
system("pause");
}
}
}
void sclsearch()
{
int i;
printf("90 分以上:\n");
printf("学号 姓名 c语言成绩\n");
for(i=0;i<100;i++)
{
if(Student[i].Chinese[0]>=90)
printf("%s %s %d\n",Student[i].number,Student[i].name,Student[i].Chinese[0]);
}
printf("80~89:\n");
printf("学号 姓名 c语言成绩\n");
for(i=0;i<100;i++)
{
if(&Student[i].Chinese[0]>=80&&Student[i].Chinese[0]<90)
printf("%s %s %d\n",Student[i].number,Student[i].name,Student[i].Chinese[0]);
}
printf("70~79:\n");
printf("学号 姓名 c语言成绩\n");
for(i=0;i<100;i++)
{
if(Student[i].Chinese[0]>=70&&Student[i].Chinese[0]<80)
printf("%s %s %d\n",Student[i].number,Student[i].name,Student[i].Chinese[0]);
}
printf("60~69:\n");
printf("学号 姓名 c语言成绩\n");
for(i=0;i<100;i++)
{
if(Student[i].score[0]>=60&&Student[i].Chinese[0]<70)
printf("%s %s %d\n",Student[i].number,Student[i].name,Student[i].Chinese[0]);
}
printf("60 分以下:\n");
printf("学号 姓名 c语言成绩\n");
for(i=0;i<00;i++)
{
if(Student[i].Chinese[0]<60)
printf("%s %s %d\n",Student[i].number,Student[i].name,Student[i].Chinese[0]);
}
}
int main(){
void Menu();
void Add();
void View();
void Delete();
void Repair();
void ViewAll();
void sclsearch();
Menu();
}
“Devil组”引证GPT后的撰写:
第六步中缺少了一个换行符,在 printf 语句最后面应该加一个换行符 \n,同时也需要添加 break 语句,以防止程序执行到后面的 case 7 中。修改后的代码如下所示:
case 6:
printf("请输入成绩范围(如60~80):");
int low, high;
scanf("%d~%d", &low, &high);
struct Student* SV;
int found = 0;
for (SV = head; SV != NULL; SV = SV->next) {
if (SV->Chinese >= low && SV->Chinese <= high) {
printf("学号:%s\t姓名:%s\n", SV->number, SV->name);
printf("c语言:%d\n", SV->Chinese);
found = 1;
}
}
if (!found) {
printf("不好意思,未找到!\n");
}
system("pause");
break;
修改后的代码应该要在 switch-case 语句块中。