求助 如何输出个学院的总分
都是第三次发帖了,着实都不好意思,无奈骑虎难下,因为停电原因延迟到今天晚上交报告,但是关于计分代码的部分,显示的都是零分。求助各方大神。#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<windows.h>
struct table_game//定义一个全局的结构体
{
char xmmc[11];//项目名称
char xymc[13];//所属学院名称
int mc; //名次
};
struct table_zf
{
char xymc[13];
int fs;
};
//定义结构体数组(全局)
struct table_game GAME[1000];
struct table_zf ZF[100];
int x = 0;//定义项目数
//定义一个全局变量存放实际的人数
int sjs = 0;
//输入比赛成绩
void input()
{
int n, i, j, index = 0;
char temp[11];
char wrong[100];//用来存放输入选择时候手误输入可能的字符
system("cls");
printf("***************************************************************************\n");
printf("*** 亲,欢迎来到运动员成绩录入功能! ***\n");
printf("***************************************************************************\n");
//sjs = 0;
for (i = sjs; i <= 999; i++)
{
printf("\n********************************************************************\n");
printf("***** 亲,是否要录入比赛成绩! *****\n");
printf("--- 1、是哒! ---\n");
printf("--- 2、不是哒! ---\n");
printf("\n********************************************************************\n");
printf("亲,请输入你的选择(1 or 2):");
scanf("%d", &n);
gets(wrong);
while (n != 1 && n != 2)
{
printf("亲,你输得不是(1 or 2),请重新输入(1 or 2):");
scanf("%d", &n);
gets(wrong);
}
if (n == 2)
{
printf("over\n");
break;
}
else
{
//正常情况下一个运动员的所有信息录入
printf("输入项目名称:");
gets(GAME[i].xmmc);
//for (j = 0; j<7; j++)
{
//GAME[index].xmmc[j] = temp[j];
int temp = 0;
printf("输入运动员所属学院名称:");
gets(GAME[i].xymc);
printf("输入名次:");
scanf("%d", &temp);
GAME[i].mc = temp;
gets(wrong);
sjs++;
}
}
}
system("pause");
}
void output()
{
int i, j;
system("cls");
printf("%-11s", "项目名称");
printf("%-13s", "所属学院名称");
printf("%-7s", "名次");
printf("\n");
for (i = 0; i <= sjs; i++)
{
printf("%-11s", GAME[i].xmmc);
printf("%-13s", GAME[i].xymc);
printf("%-7d", GAME[i].mc);
printf("\n");
}
system("pause");
}
//保存数据
void save()
{
FILE *p;
int n,i;
char wrong[100];
system("cls");
printf("************************************************************************\n");
printf("*** 亲,欢迎来到数据保存功能 ***\n");
printf("*** 1、确定保存 2、放弃保存 ***\n");
printf("************************************************************************\n");
printf("亲,请输入你的选择(1 or 2):");
scanf("%d", &n);
gets(wrong);
while (n != 1 && n != 2)
{
printf("亲,你输入的不是(1 or 2),请重新输入(1 or 2)");
scanf("%d", &n);
gets(wrong);
}
if (n == 1)
{
p = fopen("保存数据.txt", "w+");
if (p == NULL)
{
printf("数据保存失败!\n");
exit(0);
}
else
{
for (i = 0; i < sjs; i++)
{
fwrite(&GAME[i], sizeof(struct table_game), 1, p);
}
printf("亲,数据保存成功了哟!\n");
fclose(p);
}
}
else
{
printf("放弃数据保存,返回主菜单!\n");
}
system("pause");
}
//读取函数
void load()
{
FILE*p;
int n;
char wrong[100];
system("cls");
printf("************************************************************************\n");
printf("*** 亲,欢迎进入信息读取功能 ***\n");
printf("*** 1、确定读取 2、放弃读取 ***\n");
printf("************************************************************************\n");
printf("亲,请输入你的选择(1 or 2):");
scanf("%d", &n);
gets(wrong);
while (n != 1 && n != 2)
{
printf("亲,你输入的不是(1 or 2),请重新输入(1 or 2):");
scanf("%d", &n);
gets(wrong);
}
if (n == 1)
{
p = fopen("保存数据.txt", "r+");
if (p == NULL)
{
printf("文件打开失败!\n");
exit(0);
}
else
{
sjs = 0;
while (fread(&GAME[sjs], sizeof(struct table_game), 1, p))
{
sjs++;
}
printf("亲,数据读取成功了哟!\n");
fclose(p);
}
}
else
{
printf("确定放弃数据读取,即将返回主菜单\n");
}
system("pause");
}
//查询比赛成绩
void search()
{
int n, i, j, flag;
char search_xmmc[11];
int search_mc;
char search_xymc[13];
char wrong[100];
system("cls");
printf("***********************************************************************\n");
printf("*** 亲,欢迎来到查询比赛成绩功能 ***\n");
printf("*** 1、按照项目名称查询 ***\n");
printf("*** 2、按照名次查询 ***\n");
printf("*** 3、查询参赛院信息 ***\n");
printf("*** 4、退出查询 返回菜单 ***\n");
printf("***********************************************************************\n");
printf("亲,请输入你的选择(1 or 2 or 3 or 4):");
scanf("%d", &n);
gets(wrong);
while (n != 1 && n != 2 && n != 3 && n != 4)
{
printf("亲,你输入的不是(1 or 2 or 3 or 4),请重新输入(1 or 2 or 3 or 4)");
scanf("%d", &n);
gets(wrong);
}
switch (n)
{
case 1:
printf("请输入要查询的项目名称:");
gets(search_xmmc);
for (j = 0; j<sjs; j++)
{
flag = 0;
//puts(GAME[i].xmmc == 0);
if (strcmp(search_xmmc, GAME[j].xmmc) == 0)
{
flag = 1;
printf("****** 按项目名称查询有以下结果 ******\n");
printf("*** 名次 学院 ***\n ");
printf("*************************************************************\n");
printf("%7d%7s\n", GAME[j].mc, GAME[j].xymc);
break;
}
}
if (flag == 0)
{
printf("查无此项目!\n");
}
break;
case 2:
printf("请输入名次:");
scanf("%d", &search_mc);
for (j = 0; j<sjs; j++)
{
flag = 0;
//puts(GAME[i].mc == 0);
if (search_mc == GAME[j].mc)
{
flag = 1;
printf("****** 按名次查询有以下结果 ******\n");
printf("*** 项目名称 学院 ***\n ");
printf("*************************************************************\n");
printf("%11s%7s\n", GAME[j].xmmc, GAME[j].xymc);
break;
}
}
if (flag == 0)
{
printf("该名次不存在!\n");
}
break;
case 3:
printf("请输入学院名称:");
gets(search_xymc);
for (j = 0; j<sjs; j++)
{
flag = 0;
//puts(GAME[i].xymc == 0);
if (strcmp(search_xymc, GAME[j].xymc) == 0)
{
flag = 1;
printf("****** 按学院名称查询有以下结果 ******\n");
printf("*** 项目名称 名次 ***\n ");
printf("*************************************************************\n");
printf("%11s%7d\n", GAME[j].xmmc, GAME[j].mc);
break;
}
}
if (flag == 0)
{
printf("该学院不存在!\n");
}
break;
case 4: break;
}
system("pause");
}
//显示团体总分排序
void sort()
{
int i, j;
struct table_game t;
system("cls");
printf("****** 团体总分显示如下 *****\n");
printf("****** 学院 总成绩 名次 *****\n");
printf("************************************************************\n");
for (i = 0; i < sjs; i++);
{
for (j = 0; j< sjs - 1; j++)
{
if (GAME[j].mc<GAME[j + 1].mc)
{
t = GAME[j];
GAME[j] = GAME[j + 1];
GAME[j + 1] = t;
}
}
}
output();
}
//统计总分
char* get_name(int i)
{
switch (i)
{
case 1:
return "建管学院:";
case 2:
return "土木学院:";
case 3:
return "经管学院:";
case 4:
return "人文学院:";
case 5:
return "艺术学院:";
case 6:
return "电气学院:";
case 7:
return "建筑学院:";
default:
return "其他:";
}
}
void tongji()
{
int i;
char wrong[100];
system("cls");
printf("*** 亲,欢迎来到总分统计栏目 ***\n");
for (i = 0; i < sjs; i++)
{
if (GAME[i].mc == 1)
{
if (strcmp(GAME[i].xymc, "建管学院") == 0)
ZF[1].fs += 10;
if (strcmp(GAME[i].xymc, "土木学院") == 0)
ZF[2].fs += 10;
if (strcmp(GAME[i].xymc, "经管学院") == 0)
ZF[3].fs += 10;
if (strcmp(GAME[i].xymc, "人文学院") == 0)
ZF[4].fs += 10;
if (strcmp(GAME[i].xymc, "艺术学院") == 0)
ZF[5].fs += 10;
if (strcmp(GAME[i].xymc, "电气学院") == 0)
ZF[6].fs += 10;
if (strcmp(GAME[i].xymc, "建筑学院") == 0)
ZF[7].fs += 10;
}
if (GAME[i].mc == 2)
{
if (strcmp(GAME[i].xymc, "建管学院") == 0)
ZF[1].fs += 8;
if (strcmp(GAME[i].xymc, "土木学院") == 0)
ZF[2].fs += 8;
if (strcmp(GAME[i].xymc, "经管学院") == 0)
ZF[3].fs += 8;
if (strcmp(GAME[i].xymc, "人文学院") == 0)
ZF[4].fs += 8;
if (strcmp(GAME[i].xymc, "艺术学院") == 0)
ZF[5].fs += 8;
if (strcmp(GAME[i].xymc, "电气学院") == 0)
ZF[6].fs += 8;
if (strcmp(GAME[i].xymc, "建筑学院") == 0)
ZF[7].fs += 8;
}
if (GAME[i].mc == 3)
{
if (strcmp(GAME[i].xymc, "建管学院") == 0)
ZF[1].fs += 6;
if (strcmp(GAME[i].xymc, "土木学院") == 0)
ZF[2].fs += 6;
if (strcmp(GAME[i].xymc, "经管学院") == 0)
ZF[3].fs += 6;
if (strcmp(GAME[i].xymc, "人文学院") == 0)
ZF[4].fs += 6;
if (strcmp(GAME[i].xymc, "艺术学院") == 0)
ZF[5].fs += 6;
if (strcmp(GAME[i].xymc, "电气学院") == 0)
ZF[6].fs += 6;
if (strcmp(GAME[i].xymc, "建筑学院") == 0)
ZF[7].fs += 6;
}
if (GAME[i].mc == 4)
{
if (strcmp(GAME[i].xymc, "建管学院") == 0)
ZF[1].fs += 5;
if (strcmp(GAME[i].xymc, "土木学院") == 0)
ZF[2].fs += 5;
if (strcmp(GAME[i].xymc, "经管学院") == 0)
ZF[3].fs += 5;
if (strcmp(GAME[i].xymc, "人文学院") == 0)
ZF[4].fs += 5;
if (strcmp(GAME[i].xymc, "艺术学院") == 0)
ZF[5].fs += 5;
if (strcmp(GAME[i].xymc, "电气学院") == 0)
ZF[6].fs += 5;
if (strcmp(GAME[i].xymc, "建筑学院") == 0)
ZF[7].fs += 5;
}
if (GAME[i].mc == 5)
{
if (strcmp(GAME[i].xymc, "建管学院") == 0)
ZF[1].fs += 4;
if (strcmp(GAME[i].xymc, "土木学院") == 0)
ZF[2].fs += 4;
if (strcmp(GAME[i].xymc, "经管学院") == 0)
ZF[3].fs += 4;
if (strcmp(GAME[i].xymc, "人文学院") == 0)
ZF[4].fs += 4;
if (strcmp(GAME[i].xymc, "艺术学院") == 0)
ZF[5].fs += 4;
if (strcmp(GAME[i].xymc, "电气学院") == 0)
ZF[6].fs += 4;
if (strcmp(GAME[i].xymc, "建筑学院") == 0)
ZF[7].fs += 4;
}
if (GAME[i].mc == 6)
{
if (strcmp(GAME[i].xymc, "建管学院") == 0)
ZF[1].fs += 3;
if (strcmp(GAME[i].xymc, "土木学院") == 0)
ZF[2].fs += 3;
if (strcmp(GAME[i].xymc, "经管学院") == 0)
ZF[3].fs += 3;
if (strcmp(GAME[i].xymc, "人文学院") == 0)
ZF[4].fs += 3;
if (strcmp(GAME[i].xymc, "艺术学院") == 0)
ZF[5].fs += 3;
if (strcmp(GAME[i].xymc, "电气学院") == 0)
ZF[6].fs += 3;
if (strcmp(GAME[i].xymc, "建筑学院") == 0)
ZF[7].fs += 3;
}
if (GAME[i].mc == 7)
{
if (strcmp(GAME[i].xymc, "建管学院") == 0)
ZF[1].fs += 1;
if (strcmp(GAME[i].xymc, "土木学院") == 0)
ZF[2].fs += 1;
if (strcmp(GAME[i].xymc, "经管学院") == 0)
ZF[3].fs += 1;
if (strcmp(GAME[i].xymc, "人文学院") == 0)
ZF[4].fs += 1;
if (strcmp(GAME[i].xymc, "艺术学院") == 0)
ZF[5].fs += 1;
if (strcmp(GAME[i].xymc, "电气学院") == 0)
ZF[6].fs += 1;
if (strcmp(GAME[i].xymc, "建筑学院") == 0)
ZF[7].fs += 1;
}
}
for (i = 1; i < 8; i++)
{
printf("%s%d\n", get_name(i),ZF[i].fs);
}
system("pause");
}
//菜单函数
void menu()
{
time_t t;
struct tm *p;
int n;
t = time(NULL);
p = (struct tm *)localtime(&t);
system("cls");
printf(" 运动会管理系统 \n");
printf(" %d-%d-%d %d:%d:%d\n", p->tm_year + 1990, p->tm_mon + 1, p->tm_mday, p->tm_hour, p->tm_min, p->tm_sec);
printf("***********************************************************\n");
printf("--- 1、录入比赛成绩功能 ----\n");
printf("--- 2、查询各个比赛项目的成绩 ----\n");
printf("--- 3、显示团体总分报表 ----\n");
printf("--- 4、统计总分 ----\n");
printf("--- 5、保存数据 ----\n");
printf("--- 6、读取数据 ----\n");
printf("--- 7、退出系统 ----\n");
printf("***********************************************************\n");
printf("请输入你的选择(1-7):");
scanf("%d", &n);
while (n<0 || n>7)
{
printf("亲,输错了,请重新输入(1-7)");
scanf("%d", &n);
}
switch (n)
{
case 1: input(); menu(); break;
case 2: search(); menu(); break;
case 3: sort(); menu(); break;
case 4: tongji(); menu(); break;
case 5: save(); menu(); break;
case 6: load(); menu(); break;
case 7: exit(0); menu(); break;
}
}
//主函数
void main()
{
menu();//直接调用
system("pause");
}