| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 986 人关注过本帖
标题:我是C语言新手,刚学不久,可以帮帮我看看这程序吗?
只看楼主 加入收藏
陈大师
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
威 望:1
帖 子:231
专家分:1038
注 册:2009-11-4
收藏
得分:10 
我把定义的变量都提到最前就没有错误了 然后具体的内容你就要自己再仔细看看咯·····
#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,e;
char c,cc,d, u,mm[10],p;
struct STUDENT
{
  int num;
  char name[10];
  int term;
  int scoreMath;
  int scoreEnglish;
  int scoreChinese;
  float average;
  int sum;
};struct STUDENT abc;
struct STUDENT stu[1000];


printf("please enter student number:");
scanf("%d",&a);
menu();
getchar();
c=getchar();
switch(c)
{
  case '1':

           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':


           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':

           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':

           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':

                     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-06 23:10
陈大师
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
威 望:1
帖 子:231
专家分:1038
注 册:2009-11-4
收藏
得分:2 
在tc上没有错误···
2010-03-06 23:11
快速回复:我是C语言新手,刚学不久,可以帮帮我看看这程序吗?
数据加载中...
 
   



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

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