| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 986 人关注过本帖
标题:我是C语言新手,刚学不久,可以帮帮我看看这程序吗?
只看楼主 加入收藏
yintaiyuan
Rank: 1
等 级:新手上路
帖 子:21
专家分:1
注 册:2009-11-2
结帖率:77.78%
收藏
已结贴  问题点数:20 回复次数:11 
我是C语言新手,刚学不久,可以帮帮我看看这程序吗?
学生成绩管理系统: 对学生的成绩信息进行管理,学生信息包括:学号、姓名、学期、每门课程的成绩、平均成绩、名次。实现:学生信息的录入;修改;删除和查询,按学期、学号、成绩不及格等查询。

我自己编这个编个一个下午了,我辛勤的汗水啊!!!最后才发现一大堆错误,就是不会改,哪位好心人能帮帮我?居然连结构体声明那里也说我错了?

#include <stdio.h>
#include <string.h>

void menu(void)
{
 printf("1. information input\n");
 printf("2. information revise\n");
 printf("3. information delete\n");
 printf("4. information search\n");
 printf("Please enter your choice:");
}
main()
{
 int a, i, j;
 char c;
 struct STUDENT
 {
  int num;
  char name[10];
  int term;
  int scoreMath;
  int scoreEnglish;
  int scoreChinese;
  float average;
  int sum;
 };
 printf("please enter student number:");
 scanf("%d",&a);
 struct STUDENT stu[a];
4: menu();
 c=getchar();
 switch(c)
 {
  case '1':
           struct STUDENT abc;
           printf("please enter student num:");
           for(i=0;i<a;i++)
           {
            scanf("%d", &stu[i].num);
           }
           printf("please enter student name:");
           for(i=0;i<a;i++)
           {
            scanf("%s", stu[i].name);
           }
           printf("please enter term:");
           for(i=0;i<a;i++)
           {
            scanf("%d", &stu[i].term);
           }
           printf("please enter student scoreMath:");
           for(i=0;i<a;i++)
           {
            scanf("%d", &stu[i].scoreMath);
           }
           printf("please enter student scoreEnglish:");
           for(i=0;i<a;i++)
           {
            scanf("%d", &stu[i].scoreEnglish);
           }
           printf("please enter student scoreChinese:");
           for(i=0;i<a;i++)
           {
            scanf("%d", &stu[i].scoreChinese);
           }
           for(i=0;i<a;i++)
           {
            stu[i].sum=stu[i].scoreMath+stu[i].scoreEnglish+stu[i].scoreChinese;
            stu[i].average=stu[i].sum/4;
           }
           for(i=0;i<a-1;i++)
           {
            for(j=i+1;j<a;j++)
            {
             if(stu[j].sum > stu[i].sum)
             {
              abc=stu[i];
              stu[i]=stu[j];
              stu[j]=abc;
             }
            }
           }              
           for(i=0;i<a;i++)
           {
            printf("NO. : %d  Name : %s  Term : %d  ScoreMath : %d  ScoreEnglish : %d  ScoreChinese : %d  Sum : %d  Average : %f  Place: %d ", stu[i].num, stu[i].name, stu[i].term, stu[i].scoreMath, stu[i].scoreEnglish, stu[i].scoreChinese, stu[i].sum,  stu[i].average, i+1 );
           }
           goto 4;
           break;
  case '2':
           int c;
           char p;
           printf("please enter student num:");
           scanf("%d", &c);
           printf("please choice the error:");
           printf("1. num\n");
           printf("2. name\n");
           printf("3. term\n");
           printf("4. scoreMath\n");
           printf("5. scoreEnglish:");
           printf("6. scoreChinese:");
           printf("Please enter your choice:");
           p=getchar();
           switch(p)
           {
            case '1':
                     printf("please enter the new one:")
                     scanf("%d", &stu[c].num);
                     break;
            case '2':
                     printf("please enter the new one:")
                     scanf("%d", stu[c].name);
                     break;
            case '3':
                     printf("please enter the new one:")
                     scanf("%d", &stu[c].term);
                     break;
            case '4':
                     printf("please enter the new one:")
                     scanf("%d", &stu[c].scoreMath);
                     break;
            case '5':
                     printf("please enter the new one:")
                     scanf("%d", &stu[c].scoreEnglish);
                     break;

            case '6':
                     printf("please enter the new one:")
                     scanf("%d", &stu[c].scoreChinese);
                     break;
            default:
                    printf("Input error!");
           }
           for(i=0;i<a;i++)
           {
            stu[i].sum=stu[i].scoreMath+stu[i].scoreEnglish+stu[i].scoreChinese;
            stu[i].average=stu[i].sum/4;
           }
           for(i=0;i<a-1;i++)
           {
            for(j=i+1;j<a;j++)
            {
             if(stu[j].sum > stu[i].sum)
             {
              abc=stu[i];
              stu[i]=stu[j];
              stu[j]=abc;
             }
            }
           }              
           for(i=0;i<a;i++)
           {
            printf("NO. : %d  Name : %s  Term : %d  ScoreMath : %d  ScoreEnglish : %d  ScoreChinese : %d  Sum : %d  Average : %f  Place: %d ", stu[i].num, stu[i].name, stu[i].term, stu[i].scoreMath, stu[i].scoreEnglish, stu[i].scoreChinese, stu[i].sum,  stu[i].average, i+1 );
           }
           goto 4;
           break;
  case '3':
           int d;
           printf("Please enter the delete number:");
           scanf("%d", &d);
           for(i=0;i<a;i++)
           {
            if(d==stu[i].num)
            {
             for(i=0;i<a-1;i++)
             {
              stu[i]=stu[i+1];
             }
            goto 1;
            }      
           }
        1: for(i=0;i<a-1;i++)
           {
            printf("NO. : %d  Name : %s  Term : %d  ScoreMath : %d  ScoreEnglish : %d  ScoreChinese : %d  Sum : %d  Average : %f  Place: %d ", stu[i].num, stu[i].name, stu[i].term, stu[i].scoreMath, stu[i].scoreEnglish, stu[i].scoreChinese, stu[i].sum,  stu[i].average, i+1 );
           }
           goto 4;
           break;
  case '4':
           char u;
           printf("please choice the information your want to search:");
           printf("1. num\n");
           printf("2. name\n");
           printf("Please enter your choice:");
           u=getchar();
           switch(u)
           {
            case '1':
                     int e;
                     printf("Please enter the number:");
                     scanf("%d", &e);
                     for(i=0;i<a;i++)
                     {
                      if(e==stu[i].num)
                      {
            printf("NO. : %d  Name : %s  Term : %d  ScoreMath : %d  ScoreEnglish : %d  ScoreChinese : %d  Sum : %d  Average : %f  Place: %d ", stu[i].num, stu[i].name, stu[i].term, stu[i].scoreMath, stu[i].scoreEnglish, stu[i].scoreChinese, stu[i].sum,  stu[i].average, i+1 );
                      goto 2;                     
                      }
                     }
                    2: break;
            case '2':
                     char mm[10]:
                     printf("Please enter the name:");
                     scanf("%s", mm);
                     for(i=0;i<a;i++)
                     {
                      if(strcmp(mm, stu[i].name) == 0 )
                      {
            printf("NO. : %d  Name : %s  Term : %d  ScoreMath : %d  ScoreEnglish : %d  ScoreChinese : %d  Sum : %d  Average : %f  Place: %d ", stu[i].num, stu[i].name, stu[i].term, stu[i].scoreMath, stu[i].scoreEnglish, stu[i].scoreChinese, stu[i].sum,  stu[i].average, i+1 );
                      goto 3;                     
                      }
                     }
                    3: break;
            default:
                    printf("Input error!");
           }
           goto 4;
           break;
  default:
          printf("Input error!");
          goto 4;
 }
}
                                 

                     
搜索更多相关主题的帖子: C语言 
2010-03-03 20:28
浅墨
Rank: 2
等 级:论坛游民
帖 子:18
专家分:53
注 册:2010-2-6
收藏
得分:0 
你把错误发出来
2010-03-03 20:40
yintaiyuan
Rank: 1
等 级:新手上路
帖 子:21
专家分:1
注 册:2009-11-2
收藏
得分:0 
图片附件: 游客没有浏览图片的权限,请 登录注册
错误截图,其他截不了。谢谢!
2010-03-03 20:45
浅墨
Rank: 2
等 级:论坛游民
帖 子:18
专家分:53
注 册:2010-2-6
收藏
得分:2 
29:struct STUDENT stu[a];  数组声明或定义时不能用变量作为下标 应改为常量 或者宏
30:4: menu();             这个“4:” 是什么东东? 删除之
35:struct STUDENT abc;     这个。。。貌似没错
39:scanf("%d", &stu[i].num);  如果第20行声明成功 这里不需要加&符来引用num
44:scanf("%s", stu[i].name);  同上 声明成功这句没问题
 
2010-03-03 20:59
yintaiyuan
Rank: 1
等 级:新手上路
帖 子:21
专家分:1
注 册:2009-11-2
收藏
得分:0 
回复 4楼 浅墨
29:struct STUDENT stu[a];  数组声明或定义时不能用变量作为下标 应改为常量 或者宏

但是我把a改成10,也显示同样的错误啊。
2010-03-03 21:08
浅墨
Rank: 2
等 级:论坛游民
帖 子:18
专家分:53
注 册:2010-2-6
收藏
得分:1 
你可以弄一个小的test.c 只定义结构体试试 就知道了 代码太长 错误多了不好调 最好写一段调一段
2010-03-03 21:39
yintaiyuan
Rank: 1
等 级:新手上路
帖 子:21
专家分:1
注 册:2009-11-2
收藏
得分:0 
谁可以帮我改改啊~
2010-03-04 12:39
陈大师
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
威 望:1
帖 子:231
专家分:1038
注 册:2009-11-4
收藏
得分:5 
只是改了一下一些地方,使得这个程序没有错误···还有这个系统还没有储存功能,所以只有第一项功能即”添加“学生信息可以实线,其他的暂时还不能,还需要你自己再完善。。。
#include <stdio.h>
#include <string.h>

void menu(void)
{
printf("1. information input\n");
printf("2. information revise\n");
printf("3. information delete\n");
printf("4. information search\n");
printf("Please enter your choice:");
}
main()
{
int a, i, j;
char c;
struct STUDENT
{
  int num;
  char name[10];
  int term;
  int scoreMath;
  int scoreEnglish;
  int scoreChinese;
  float average;
  int sum;
};
struct STUDENT stu[1000];//先开一个够大的结构体数组
printf("please enter student number:");//学生的总人数
scanf("%d",&a);
menu();
getchar();//这个很好用,是用来吸收每次按Enter这个字符,消除错误!
c=getchar();
switch(c)
{
  case '1'://目前只有这一项功能可以使用
           struct STUDENT abc;
           printf("please enter student num:");
           getchar();
           for(i=0;i<a;i++)
           {
            scanf("%d", &stu[i].num);getchar();
           }
           printf("please enter student name:");
           
           for(i=0;i<a;i++)
           {
            scanf("%s", stu[i].name);
           }
           printf("please enter term:");
           getchar();
           for(i=0;i<a;i++)
           {
            scanf("%d", &stu[i].term);
           }
           printf("please enter student scoreMath:");
           getchar();
           for(i=0;i<a;i++)
           {
            scanf("%d", &stu[i].scoreMath);
           }
           printf("please enter student scoreEnglish:");
           getchar();
           for(i=0;i<a;i++)
           {
            scanf("%d", &stu[i].scoreEnglish);
           }
           printf("please enter student scoreChinese:");
           getchar();
           for(i=0;i<a;i++)
           {
            scanf("%d", &stu[i].scoreChinese);
           }
           for(i=0;i<a;i++)
           {
            stu[i].sum=stu[i].scoreMath+stu[i].scoreEnglish+stu[i].scoreChinese;
            stu[i].average=stu[i].sum/4;
           }
           for(i=0;i<a-1;i++)
           {
            for(j=i+1;j<a;j++)
            {
             if(stu[j].sum > stu[i].sum)
             {
              abc=stu[i];
              stu[i]=stu[j];
              stu[j]=abc;
             }
            }
           }              
           for(i=0;i<a;i++)
           {
            printf("NO. : %d  Name : %s  Term : %d  ScoreMath : %d  ScoreEnglish : %d  ScoreChinese : %d  Sum : %d  Average : %f  Place: %d ", stu[i].num, stu[i].name, stu[i].term, stu[i].scoreMath, stu[i].scoreEnglish, stu[i].scoreChinese, stu[i].sum,  stu[i].average, i+1 );
            printf("\n\n");
          }
           menu();
           break;
  case '2':
           int c;
           char p;
           printf("please enter student num:");
           scanf("%d", &c);
           printf("please choice the error:");
           printf("1. num\n");
           printf("2. name\n");
           printf("3. term\n");
           printf("4. scoreMath\n");
           printf("5. scoreEnglish:");
           printf("6. scoreChinese:");
           printf("Please enter your choice:");
           p=getchar();
           switch(p)
           {
            case '1':
                     printf("please enter the new one:");
                     scanf("%d", &stu[c].num);
                     break;
            case '2':
                     printf("please enter the new one:");
                     scanf("%d", stu[c].name);
                     break;
            case '3':
                     printf("please enter the new one:");
                     scanf("%d", &stu[c].term);
                     break;
            case '4':
                     printf("please enter the new one:");
                     scanf("%d", &stu[c].scoreMath);
                     break;
            case '5':
                     printf("please enter the new one:");
                     scanf("%d", &stu[c].scoreEnglish);
                     break;

            case '6':
                     printf("please enter the new one:");
                     scanf("%d", &stu[c].scoreChinese);
                     break;
            default:
                    printf("Input error!");
           }
           for(i=0;i<a;i++)
           {
            stu[i].sum=stu[i].scoreMath+stu[i].scoreEnglish+stu[i].scoreChinese;
            stu[i].average=stu[i].sum/4;
           }
           for(i=0;i<a-1;i++)
           {
            for(j=i+1;j<a;j++)
            {
             if(stu[j].sum > stu[i].sum)
             {
              abc=stu[i];
              stu[i]=stu[j];
              stu[j]=abc;
             }
            }
           }              
           for(i=0;i<a;i++)
           {
            printf("NO. : %d  Name : %s  Term : %d  ScoreMath : %d  ScoreEnglish : %d  ScoreChinese : %d  Sum : %d  Average : %f  Place: %d ", stu[i].num, stu[i].name, stu[i].term, stu[i].scoreMath, stu[i].scoreEnglish, stu[i].scoreChinese, stu[i].sum,  stu[i].average, i+1 );
            printf("\n\n");           
           }
           menu();
           break;
  case '3':
           int d;
           printf("Please enter the delete number:");
           scanf("%d", &d);
           for(i=0;i<a;i++)
           {
            if(d==stu[i].num)
            {
             for(i=0;i<a-1;i++)
             {
              stu[i]=stu[i+1];
             }
            for(i=0;i<a-1;i++)
           {
            printf("NO. : %d  Name : %s  Term : %d  ScoreMath : %d  ScoreEnglish : %d  ScoreChinese : %d  Sum : %d  Average : %f  Place: %d ", stu[i].num, stu[i].name, stu[i].term, stu[i].scoreMath, stu[i].scoreEnglish, stu[i].scoreChinese, stu[i].sum,  stu[i].average, i+1 );
           printf("\n\n");
            }

            }      
           }        
           menu();
           break;
  case '4':
           char u; char mm[10];
           printf("please choice the information your want to search:");
           printf("1. num\n");
           printf("2. name\n");
           printf("Please enter your choice:");
           u=getchar();
           switch(u)
           {
            case '1':
                     int e;
                     printf("Please enter the number:");
                     scanf("%d", &e);
                     for(i=0;i<a;i++)
                     {
                      if(e==stu[i].num)
                      {
            printf("NO. : %d  Name : %s  Term : %d  ScoreMath : %d  ScoreEnglish : %d  ScoreChinese : %d  Sum : %d  Average : %f  Place: %d ", stu[i].num, stu[i].name, stu[i].term, stu[i].scoreMath, stu[i].scoreEnglish, stu[i].scoreChinese, stu[i].sum,  stu[i].average, i+1 );
                       break;                     
                      }
                     }
                    
            case '2':
                    
                     printf("Please enter the name:");
                     scanf("%s", mm);
                     for(i=0;i<a;i++)
                     {
                      if(strcmp(mm, stu[i].name) == 0 )
                      {
            printf("NO. : %d  Name : %s  Term : %d  ScoreMath : %d  ScoreEnglish : %d  ScoreChinese : %d  Sum : %d  Average : %f  Place: %d ", stu[i].num, stu[i].name, stu[i].term, stu[i].scoreMath, stu[i].scoreEnglish, stu[i].scoreChinese, stu[i].sum,  stu[i].average, i+1 );
                      printf("\n\n");
                      break;                     
                      }
                     }
                    
            default:
                    printf("Input error!");
           }
           
           menu();
           break;
  default:
          printf("Input error!");
          menu();
}
}
                                 

2010-03-04 21:38
坏坏的傻子
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2010-2-28
收藏
得分:0 
厉害
2010-03-04 21:50
yintaiyuan
Rank: 1
等 级:新手上路
帖 子:21
专家分:1
注 册:2009-11-2
收藏
得分:0 
回复 8楼 陈大师
谢谢你啊,在VC下编译是可以通过的,但是在TC2.0上编译很多错误,有办法可以在TC2.0上通过吗?谢谢!
2010-03-04 23:14
快速回复:我是C语言新手,刚学不久,可以帮帮我看看这程序吗?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.023999 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved