user-0 提问: 求大佬帮帮忙，统计函数部分一直不成功，求修改（C语言，数据结构，顺序存储）

回复:
user: user-1
content: 引用 7 楼 笑欢浮生若梦的回复:谢谢解答，第一次做这一类作业，谢谢 不客气，哈哈哈我也是个小白

user: user-0
content: 谢谢解答，第一次做这一类作业，谢谢

user: user-1
content: # 基本编译错误帮你解决咯，建议代码多写注释，不然别人看着吃力 #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX_STR_LEN 20 #define MAX_COURSE_NUM 10 /*定义Course结构体 参数： id:课程编号 name:课程名称 Score：学分 Date:开课日期 */ typedef struct course { 	int id; 	char name; 	int score, date; }COURSE; //显示菜单 void getHome(); //插入课程信息// int Insert(COURSE course[], int num); //打印课程信息 void PrintLine(COURSE course[], int num); //查询课程信息 int Search(COURSE course[], int course_id); //删除课程信息 int Delete(COURSE course[], int course_id); //此学期的课数总计 int ComputeSumDate(COURSE course[], int course_date);  int main() { 	COURSE a[MAX_COURSE_NUM];//定义数组a[10] 	COURSE course; 	int res, num, course_id, course_date; 	int command;//指令  	while (1) { 		getHome();//显示菜单 		scanf("%d", &command);//提示用户输入指令 		getchar();//用于清除“/n” 		fflush(stdin);//清空缓存区 		switch (command) { 		case 1: 			printf("input the number of course\n"); 			scanf("%d", &num);//课程编号 			fflush(stdin); 			if (num>MAX_COURSE_NUM) { 				printf("Exceeds the maximum\n"); 				continue; 			} 			res = Insert(a, num); 			if (res == 2) { 				printf("success!\n"); 			} 			else { 				printf("false!\n"); 			} 			break; 		case 2: 			printf("input the course id you want to del:\n"); 			scanf("%d", &course_id); 			fflush(stdin); 			res = Search(a, course_id); 			if (res == -1) { 				printf("the course is not exist\n"); 			} 			else { 				Delete(a, res); 				num = num - 1; 			} 			break; 		case 3: 			printf("input the course number you want to search\n"); 			scanf("%d", &course_id); 			fflush(stdin); 			res = Search(a, course_id); 			if (res == -1) { 				printf("the course is not exist\n"); 			} 			else { 				printf("%d\n", res); 			} 			break; 		case 4: 			PrintLine(a, num); 			break; 		case 5: 			printf("input the course date you want to count\n"); 			scanf("%d", &course_date); 			fflush(stdin); 			res = ComputeSumDate(a, course_date); 			if (res == -1) { 				printf("the course is not exist\n"); 			} 			else { printf("%d\n", res); } 			break; 		case 6: 			return 0; 		default: 			printf("input error!\n"); 			break; 		}   	}    } int Insert(COURSE course[], int num) { 	int i; 	for (i = 0; i <= num - 1; i++) { 		printf("input the course id:\n"); 		scanf("%d", &course[i].id); 		fflush(stdin); 		printf("input the course name:\n"); 		scanf("%s", &course[i].name); 		printf("input the course date:\n"); 		scanf("%d", &course[i].date); 		printf("input the course score\n"); 		scanf("%d", &course[i].score); 		fflush(stdin); 	} 	return 2; } void PrintLine(COURSE course[], int num) { 	int i; 	if (num == 0) { 		printf("the course array is null\n"); 	} 	else { 		for (i = 0; i<num; i++) {  			printf("编号:%d 名字:%s 学分:%d 开课日期：%d,", course[i].id, &course[i].name, course[i].score, course[i].date); 			printf("\n");  		}   	} } int Search(COURSE course[], int course_id) { 	int i; 	for (i = 0; i <= MAX_COURSE_NUM; i++) { 		if (course[i].id == course_id) { 			printf("编号:%d,名字:%s,学分:%d,开课日期：%d,", course[i].id, &course[i].name, course[i].score, course[i].date); 			return i + 1; 		} 	} 	return -1; } int Delete(COURSE course[], int course_id) { 	int j; 	for (j = course_id; j <= MAX_COURSE_NUM; j++) { 		course[j - 1].id = course[j].id; 		course[j - 1].name = course[j].name; 		course[j - 1].score = course[j].score; 	} 	printf("success!\n"); 	return 1;  } int ComputeSumDate(COURSE course[], int course_date) { 	{ 		int i, sum = 0; 		for (i = 0; i <= MAX_COURSE_NUM - 1; i++) { 			if (course[i].date == course_date) 			{ 				sum++; 				i++; 			} 			else { i++; } 			printf("此学期的课数总计：%d\n", i); 		} 		return i; 	} 	return -1; }  void getHome() { 	printf("1.Insert course\n2.Del course\n3.Search course\n4.Display all course\n5.Count\n6.exit\n"); }

user: user-1
content: 引用 2 楼 user-2_16_com的回复: int  home="1.Insert course\n2.Del course\n3.Search course\n4.Display all course\n5.Coun    t\n6.exit\n";  写的啥玩意儿。 这个是想显示菜单，怎么能用整型变量来搞呢，直接定义一个函数不就行了

user: user-2
content: 看着像是大学生的作业，这种类似的问题实在是太多了  #include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX_STR_LEN 20 #define MAX_COURSE_NUM 10 /*定义Course结构体   参数： id:课程编号 name:课程名称 Score：学分 Date:开课日期  */ typedef struct course{ 	int id; 	char name[MAX_STR_LEN]; 	int score; 	int date; }COURSE; //插入课程信息// int Insert(COURSE course[],int num); //打印课程信息 void PrintLine(COURSE course[],int num); //查询课程信息 int Search(COURSE course[],int course_id); //删除课程信息 int Delete(COURSE course[],int course_id);  int ComputeSumDate(COURSE course[],int course_date);  int main(){ 	COURSE a[MAX_COURSE_NUM]; 	COURSE course; 	int res,num,course_id,course_date; 	int command; 	char home[]="1.Insert course\n2.Del course\n3.Search course\n4.Display all course\n5.Count\n6.exit\n";  	while(1){ 		printf("%s",home); 		scanf("%d",&command); 		fflush(stdin);//清空缓存区 		switch(command){ 			case 1: 				printf("input the number of course\n"); 				scanf("%d",&num); 				fflush(stdin); 				if(num>MAX_COURSE_NUM){ 					printf("Exceeds the maximum\n"); 					continue; 				} 				res=Insert(a,num); 				if(res==2){ 					printf("success!\n"); 				}else{ 					printf("false!\n"); 				} 				break; 			case 2: 				printf("input the course id you want to del:\n"); 				scanf("%d",&course_id); 				fflush(stdin); 				res=Search(a,course_id); 				if(res==-1){ 					printf("the course is not exist\n"); 				}else{ 					Delete(a,res); 					num=num-1; 				} 				break; 			case 3: 				printf("input the course number you want to search\n"); 				scanf("%d",&course_id); 				fflush(stdin); 				res=Search(a,course_id); 				if(res==-1){ 					printf("the course is not exist\n"); 				}else{ 					printf("%d\n",res); 				} 				break; 			case 4: 				PrintLine(a,num); 				break; 			case 5: 				printf("input the course date you want to count\n"); 				scanf("%d",&course_date); 				fflush(stdin); 				res=ComputeSumDate(a,course_date); 				if(res==-1){ 					printf("the course is not exist\n"); 				}else{ printf("%d\n",res);} 				break; 			case 6: 				return 0; 			default : 				printf("input error!\n"); 				break; 		} 		command = -1;   	}    } int Insert(COURSE course[],int num){ 	int i; 	for(i=0;i<=num-1;i++){ 		printf("input the course id:\n"); 		scanf("%d",&course[i].id); 		fflush(stdin); 		printf("input the course name:\n"); 		scanf("%s",course[i].name); 		printf("input the course date:\n"); 		scanf("%d",&course[i].date); 		printf("input the course score\n"); 		scanf("%d",&course[i].score); 		fflush(stdin);   	} 	return 2; } void PrintLine(COURSE course[],int num){ 	int i; 	if(num==0){ 		printf("the course array is null\n"); 	}else{ 		for(i=0;i<num;i++){  			printf("编号:%d,名字:%s,学分:%d,开课日期：%d,",course[i].id,course[i].name,course[i].score,course[i].date); 			printf("\n");  		}   	} } int Search(COURSE course[],int course_id){ 	int i; 	for(i=0;i<=MAX_COURSE_NUM;i++){ 		if(course[i].id==course_id){ 			printf("编号:%d,名字:%s,学分:%d,开课日期：%d,",course[i].id,course[i].name,course[i].score,course[i].date); 			return i+1; 		} 	} 	return -1; } int Delete(COURSE course[],int course_id){ 	int j; 	for(j=course_id;j<=MAX_COURSE_NUM;j++){ 		course[j-1].id=course[j].id; 		strcpy(course[j-1].name, course[j].name); 		//course[j-1].name=course[j].name; 		course[j-1].score=course[j].score; 	} 	printf("success!\n"); 	return 1;  } int ComputeSumDate(COURSE course[],int course_date){ 	{ 		int i,sum=0; 		for(i=0;i<=MAX_COURSE_NUM-1;i++){ 			if(course[i].date==course_date) 			{sum++; 				i++; 			} 			else{i++;}  			printf("此学期的课数总计：%d\n",i); 		}  	} 	return -1; }

user: user-2
content: int  home="1.Insert course\n2.Del course\n3.Search course\n4.Display all course\n5.Coun    t\n6.exit\n";  写的啥玩意儿。

user: user-1
content: 你说的统计函数，上面我没有改，你改成下面这样就没问题了  int ComputeSumDate(COURSE course[], int course_date) { 	{ 		int i, sum = 0; 		for (i = 0; i <= MAX_COURSE_NUM - 1; i++) { 			if (course[i].date == course_date) 			{ 				sum++; 				i++; 			} 		} 		printf("此学期的课数总计：%d\n", sum); 		return i; 	} 	return -1; }