| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 565 人关注过本帖
标题:能不能帮我看一下,这个哪里有出错吗?
只看楼主 加入收藏
hqfjpt
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2011-6-23
结帖率:75%
收藏
已结贴  问题点数:15 回复次数:10 
能不能帮我看一下,这个哪里有出错吗?

#include "stdio.h"
#include "conio.h"
#include "stdlib.h"
#include "string.h"
#define N  3

struct student
 { long int number;
   char name[10];
   float s[5],sum,ave;
 }temp,stu[N]= {{10010,"lin",1,1,1,1,1},
                {10011,"huang",0,0,0,0,0},
                {10012,"cheng",2,2,2,2,2}
               };
void print(struct student stu[ ],int i)
 { int  j;
   printf("||number||    name||\n");
   printf("||%ld ||%8s||\n",stu[i].number,stu[i].name);
   for (j=0;j<5;j++)
   printf("score%d=:%8.1f\n",j+1,stu[i].s[j]);
   printf("\n");

  }
void Input(struct student stu[ ],int i)
 { int  j;
   float k;
     printf("Please input the student's number=:");
     scanf("%ld",&stu[i].number);
     printf("Please input the student's name=:");
     scanf("%s",&stu[i].name);
     for (j=0;j<5;j++)
        {printf("Please input the student's score%d=:",j+1);
         scanf("%f",&k);
         stu[i].s[j]=k;
        }
      print(stu,i);
  }


 void Add(struct student stu[ ],int i)
 { int  j;
   float k;
     printf("Please input the student's number=:");
     scanf("%ld",&stu[i+N-1].number);
     printf("Please input the student's name=:");
     scanf("%s",&stu[i+N-1].name);
     for (j=0;j<5;j++)
        {printf("Please input the student's score%d=:",j+1);
         scanf("%f",&k);
         stu[i+N-1].s[j]=k;
        }
      for(j=0;j<N+1;j++)
      {print(stu,j);}
  }

 void Change(struct student stu[ ],int i)
 {  int j,k;
   long int m;
   float p;
   printf("Please input the student's number:\n");
   scanf("%ld",&m);
   for(j=0;j<N;j++)
   {  if (stu[j].number==m)
      {  k=j;
       print(stu,j);
       printf("\n");
       }
   }
     do
    {printf("\t\t\t***  1.Change     the  student's score1     ***\t\t\t\n");
     printf("\t\t\t***  2.Change     the  student's score2     ***\t\t\t\n");
     printf("\t\t\t***  3.Change     the  student's score3     ***\t\t\t\n");
     printf("\t\t\t***  4.Change     the  student's score4     ***\t\t\t\n");
     printf("\t\t\t***  5.Change     the  student's score5     ***\t\t\t\n");
     printf("Please input i=:\n");
     scanf("%d",&i);
     switch (i)
      { case 1:printf("Please input the student's score1:\n");
              scanf("%f",&p);
              stu[k].s[0]=p;
              print(stu,k);break;
        case 2:printf("Please input the student's score2:\n");
              scanf("%f",&p);
              stu[k].s[1]=p;
              print(stu,k);break;
        case 3:printf("Please input the student's score3:\n");
              scanf("%f",&p);
              stu[k].s[2]=p;
           print(stu,k);break;
        case 4:printf("Please input the student's score4:\n");
              scanf("%f",&p);
              stu[k].s[3]=p;
             print(stu,k);break;
        case 5:printf("Please input the student's score5:\n");
              scanf("%f",&p);
              stu[k].s[4]=p;
              print(stu,k);break;
      }}while (i!=0);
      printf("please wait input any key continue");
      getch();
    }
 void Delete (struct student stu[ ],int i)
 { long int m;
   printf("Please input the student's number=:\n");
   scanf("%ld",&m);
   for(i=0;i<N;i++)
   {  if (stu[i].number==m)
      {  stu[i]=stu[i+1];
       }
    }
    for(i=0;i<N-1;i++)
    { print(stu,i);
     }
 }
 void Inquire(struct student stu[ ],int i)
 { long int m;
   printf("Please input the student's number=:\n");
   scanf("%ld",&m);
   for(i=0;i<N;i++)
   {  if (stu[i].number==m)
      { print(stu,i);
       }
   }
   printf("please wait input any key continue");
   getch();
}
  void Sort(struct student stu[ ],int i)
  {int j;
   float a;
    for (i=0;i<N;i++)
     {for (j=0;j<5;j++)
       {a=0;
        a+=stu[i].s[j];
        stu[i].sum=a;
        print(stu,i);
        printf("%8.1f\n",stu[i].sum);
        }
      }
     for (i=0;i<N;i++)
      {for (j=0;j<N+1;j++)
        {if (stu[i].sum>stu[j].sum)
           {temp=stu[i];
            stu[i]=stu[j];
            stu[j]=temp;
            }
        }
        print(stu,i);
        printf("%8.1f\n",stu[i].sum);
       }
       printf("please wait input any key continue");
       getch();
   }
 void Statistics(struct student stu[ ],int i)
 {int j,m=0,b=0;
   for (i=0;i<3;i++)
     for (j=0;j<5;j++)
       {if (stu[i].s[j]<60)
          { m++;
            printf("||number||name||\n");
            printf("||%ld||%s||\n",stu[i].number,stu[i].name);
           }
       }
       printf("the student don't pass exam have:%d\n",m);
       for (i=0;i<3;i++)
           for (j=0;j<5;j++)
           {  if (stu[i].s[j]>80)
               {b++;
                printf("||number||name||\n");
                printf("||%ld||%s||\n",stu[i].number,stu[i].name);
               }
           }
           printf("the student  pass exam have:%d\n",b);
}



main()
 {  int select,i=0;
    float k;
    do
    {
    printf("\t\t\t***--------------------------------------------***\t\t\t\n");
    printf("\t\t\t***                                            ***\t\t\t\n");
    printf("\t\t\t***  Welcome to The Student's Mangement System ***\t\t\t\n");
    printf("\t\t\t***                                            ***\t\t\t\n");
    printf("\t\t\t***--------------------------------------------***\t\t\t\n");
    printf("\t\t\t***  1.Input      the  student's date          ***\t\t\t\n");
    printf("\t\t\t***  2.Add        the  student's date          ***\t\t\t\n");
    printf("\t\t\t***  3.Delete     the  student's date          ***\t\t\t\n");
    printf("\t\t\t***  4.Change     the  student's date          ***\t\t\t\n");
    printf("\t\t\t***  5.Inquire    the  student's date          ***\t\t\t\n");
    printf("\t\t\t***  6.Sort       the  student's date          ***\t\t\t\n");
    printf("\t\t\t***  7.Statistics the  student's date          ***\t\t\t\n");
    printf("\t\t\t***  0.Escape     the  student's system        ***\t\t\t\n");
    printf("Please input select=:\n");
    scanf("%d",&select);
      switch (select)
      {  case 1:Input(stu,i);break;
         case 2:Add(stu,i);break;
         case 3:Delete(stu,i);break;
         case 4:Change(stu,i);break;
         case 5:Inquire(stu,i);break;
         case 6:Sort(stu,i);break;
         case 7:Statistics(stu,i);break;
         default:printf("It's wrong");break;
       }
    }while(select!=0);
 }
搜索更多相关主题的帖子: 10010 long include number huang 
2011-06-26 01:43
voidx
Rank: 12Rank: 12Rank: 12
来 自:邯郸
等 级:火箭侠
帖 子:1250
专家分:3538
注 册:2011-4-7
收藏
得分:0 
你先说说哪里错了。
我运行了一下,好像还挺对的
2011-06-26 02:05
zjl01223
Rank: 2
等 级:论坛游民
帖 子:42
专家分:90
注 册:2011-4-21
收藏
得分:0 
我这里编译也没问题,只有一个未引用局部变量K的警告,能运行。
可能是LZ编译器的问题
2011-06-26 10:26
zjl01223
Rank: 2
等 级:论坛游民
帖 子:42
专家分:90
注 册:2011-4-21
收藏
得分:0 
do
while
不要了
2011-06-26 14:20
hqfjpt
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2011-6-23
收藏
得分:0 
是菜单的do while吗?我试了一下,好像还是不行呀!
2011-06-26 14:44
hqfjpt
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2011-6-23
收藏
得分:0 
每次输入数据后,都直接没了,没有再输出数据,我是想输入后输出一个类似表格的东西
2011-06-26 14:46
zjl01223
Rank: 2
等 级:论坛游民
帖 子:42
专家分:90
注 册:2011-4-21
收藏
得分:0 
程序代码:
#include "stdio.h"
#include "conio.h"
#include "stdlib.h"
#include "string.h"
#define N  3

struct student
{  int number;
   char name[10];
   float s[5];
   float sum;
   float ave;
}temp,stu[N];

void print(struct student stu[ ],int i)
{
    int  j;
    for(i=0;i<N;i++)
    {
        printf("||number||    name||\n");
        printf("||%d ||%8s||\n",stu[i].number,stu[i].name);
        for (j=0;j<5;j++)
            printf("score%d=:%5.1f||",j+1,stu[i].s[j]);
        printf("\n");
}
}
void Input(struct student stu[ ],int i)
{ int  j;
   float k;
   for(i=0;i<N;i++)
   {
     printf("Please input the student's number=:");
     scanf("%ld",&stu[i].number);
     printf("Please input the student's name=:");
     scanf("%s",&stu[i].name);
     for (j=0;j<5;j++)
        {printf("Please input the student's score%d=:",j+1);
         scanf("%f",&k);
         stu[i].s[j]=k;
        }
   }
      print(stu,i);
  }


void Add(struct student stu[ ],int i)
{ int  j;
   float sum=0;
   Input(stu,i);
     printf("Please input the student's number=:");
     scanf("%ld",&stu[i].number);
     for (j=0;j<5;j++)
         sum+=stu[i].s[j];
     printf("number%ld the sum is:%f\n",stu[i].number,sum);
  }

void Change(struct student stu[ ],int i)
{  int j,k;
   long int m;
   float p;
   printf("Please input the student's number:\n");
   scanf("%ld",&m);
   for(j=0;j<N;j++)
   {  if (stu[j].number==m)
      {  k=j;
       print(stu,j);
       printf("\n");
       }
   }
     do
    {printf("\t\t\t***  1.Change     the  student's score1     ***\t\t\t\n");
     printf("\t\t\t***  2.Change     the  student's score2     ***\t\t\t\n");
     printf("\t\t\t***  3.Change     the  student's score3     ***\t\t\t\n");
     printf("\t\t\t***  4.Change     the  student's score4     ***\t\t\t\n");
     printf("\t\t\t***  5.Change     the  student's score5     ***\t\t\t\n");
     printf("Please input i=:\n");
     scanf("%d",&i);
     switch (i)
      { case 1:printf("Please input the student's score1:\n");
              scanf("%f",&p);
              stu[k].s[0]=p;
              print(stu,k);break;
        case 2:printf("Please input the student's score2:\n");
              scanf("%f",&p);
              stu[k].s[1]=p;
              print(stu,k);break;
        case 3:printf("Please input the student's score3:\n");
              scanf("%f",&p);
              stu[k].s[2]=p;
           print(stu,k);break;
        case 4:printf("Please input the student's score4:\n");
              scanf("%f",&p);
              stu[k].s[3]=p;
             print(stu,k);break;
        case 5:printf("Please input the student's score5:\n");
              scanf("%f",&p);
              stu[k].s[4]=p;
              print(stu,k);break;
      }}while (i!=0);
      printf("please wait input any key continue");
      getch();
    }
void Delete (struct student stu[ ],int i)
{ long int m;
   printf("Please input the student's number=:\n");
   scanf("%ld",&m);
   for(i=0;i<N;i++)
   {  if (stu[i].number==m)
      {  stu[i]=stu[i+1];
       }
    }
    for(i=0;i<N-1;i++)
    { print(stu,i);
     }
}
void Inquire(struct student stu[ ],int i)
{ long int m;
   printf("Please input the student's number=:\n");
   scanf("%ld",&m);
   for(i=0;i<N;i++)
   {  if (stu[i].number==m)
      { print(stu,i);
       }
   }
   printf("please wait input any key continue");
   getch();
}
  void Sort(struct student stu[ ],int i)
  {int j;
   float a;
    for (i=0;i<N;i++)
     {for (j=0;j<5;j++)
       {a=0;
        a+=stu[i].s[j];
        stu[i].sum=a;
        print(stu,i);
        printf("%8.1f\n",stu[i].sum);
        }
      }
     for (i=0;i<N;i++)
      {for (j=0;j<N+1;j++)
        {if (stu[i].sum>stu[j].sum)
           {temp=stu[i];
            stu[i]=stu[j];
            stu[j]=temp;
            }
        }
        print(stu,i);
        printf("%8.1f\n",stu[i].sum);
       }
       printf("please wait input any key continue");
       getch();
   }
void Statistics(struct student stu[ ],int i)
{int j,m=0,b=0;
   for (i=0;i<3;i++)
     for (j=0;j<5;j++)
       {if (stu[i].s[j]<60)
          { m++;
            printf("||number||name||\n");
            printf("||%ld||%s||\n",stu[i].number,stu[i].name);
           }
       }
       printf("the student don't pass exam have:%d\n",m);
       for (i=0;i<3;i++)
           for (j=0;j<5;j++)
           {  if (stu[i].s[j]>80)
               {b++;
                printf("||number||name||\n");
                printf("||%ld||%s||\n",stu[i].number,stu[i].name);
               }
           }
           printf("the student  pass exam have:%d\n",b);
}



main()
{  int select,i=0;
    float k;
    printf("\t\t\t***--------------------------------------------***\t\t\t\n");
    printf("\t\t\t***                                            ***\t\t\t\n");
    printf("\t\t\t***  Welcome to The Student's Mangement System ***\t\t\t\n");
    printf("\t\t\t***                                            ***\t\t\t\n");
    printf("\t\t\t***--------------------------------------------***\t\t\t\n");
    printf("\t\t\t***  1.Input      the  student's date          ***\t\t\t\n");
    printf("\t\t\t***  2.Add        the  student's date          ***\t\t\t\n");
    printf("\t\t\t***  3.Delete     the  student's date          ***\t\t\t\n");
    printf("\t\t\t***  4.Change     the  student's date          ***\t\t\t\n");
    printf("\t\t\t***  5.Inquire    the  student's date          ***\t\t\t\n");
    printf("\t\t\t***  6.Sort       the  student's date          ***\t\t\t\n");
    printf("\t\t\t***  7.Statistics the  student's date          ***\t\t\t\n");
    printf("\t\t\t***  0.Escape     the  student's system        ***\t\t\t\n");
    printf("Please input select=:\n");
    scanf("%d",&select);
      switch (select)
      {  case 1:Input(stu,i);break;
         case 2:Add(stu,i);break;
         case 3:Delete(stu,i);break;
         case 4:Change(stu,i);break;
         case 5:Inquire(stu,i);break;
         case 6:Sort(stu,i);break;
         case 7:Statistics(stu,i);break;
         default:printf("It's wrong");break;
       }
   
}

刚改了一点,
2011-06-26 15:20
hqfjpt
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2011-6-23
收藏
得分:0 
可是为什么我运行case1时候,总是输入后就跳出呢?没有输出数据
2011-06-26 15:31
hqfjpt
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2011-6-23
收藏
得分:0 
回复 7楼 zjl01223
可是为什么我运行case1时候,总是输入后就跳出呢?没有输出数据
2011-06-26 15:54
zjl01223
Rank: 2
等 级:论坛游民
帖 子:42
专家分:90
注 册:2011-4-21
收藏
得分:15 
程序代码:
#include "stdio.h"
#include "conio.h"
#include "stdlib.h"
#include "string.h"
#define N  3

struct student
{  int number;
   char name[10];
   float s[5];
   float sum;
   float ave;
}temp,stu[N]={{10010,"lin",2,1,1,86,96},
{10011,"huang",0,82,0,25,0}};


void print(struct student stu[ ],int i)
{
    int j;
    float sum=0,ave=0;
    for(i=0;i<N;i++)
    {   sum=0;         //*循环一次sum归零*//
        printf("| number| name | score1 | score2 | score3 | score4 | score5 | sum  | ave  |\n");
        printf("| %d  |%-8s|",stu[i].number,stu[i].name);
        for (j=0;j<5;j++)
        {   
            printf(" %5.1f |",stu[i].s[j]);
            sum+=stu[i].s[j];                  //*求总分数*//
            stu[i].sum=sum;
            stu[i].ave=stu[i].sum/5;           //*求平均分*//
        }
        printf(" %5.1f | %5.1f |",stu[i].sum,stu[i].ave);
        printf("\n");
    }
}
void Input(struct student stu[ ],int i)
{
   int num=0, j;
   if(num!=N)
   {
       printf("Please input the student's number=:");
       scanf("%ld",&stu[i].number);
       printf("Please input the student's name=:");
       scanf("%s",stu[i].name);
       for (j=0;j<5;j++)
       {
           printf("Please input the student's score%d=:",j+1);
           scanf("%f",&stu[i].s[j]);
        }
       num=num+1;
       print(stu,i);
   }
   else printf("数据库已满\n");
  }


void Search(struct student stu[ ],int i)      //*可能跟后面的Inquire重复了,因为不知道原来的Add要做什么*//
{
    int number0 ,j;
    float sum=0,ave=0;
    printf("Please input the student's number=:");
    scanf("%d",&number0);
    i=0;
    while(stu[i].number!=number0&&i!=N)
        i++;
    if(stu[i].number==number0)
    {
        printf("| number| name | score1 | score2 | score3 | score4 | score5 | sum  | ave  |\n");
        printf("| %d  |%-8s|",stu[i].number,stu[i].name);
        for (j=0;j<5;j++)
            printf(" %5.1f  |",stu[i].s[j]);
        for (j=0;j<5;j++)
            sum+=stu[i].s[j];
        stu[i].sum=sum;
        stu[i].ave=stu[i].sum/5;
        printf("% 5.1f | %5.1f ",stu[i].sum,stu[i].ave);
        printf("\n");
    }
     else printf("don't have the number\n");
}

void Change(struct student stu[ ],int i)
{  int j,k;
   long int m;
   float p;
   printf("Please input the student's number:\n");
   scanf("%ld",&m);
   for(j=0;j<N;j++)
   {  if (stu[j].number==m)
      {  k=j;
       print(stu,j);
       printf("\n");
       }
   }
     do
    {printf("\t\t\t***  1.Change     the  student's score1     ***\t\t\t\n");
     printf("\t\t\t***  2.Change     the  student's score2     ***\t\t\t\n");
     printf("\t\t\t***  3.Change     the  student's score3     ***\t\t\t\n");
     printf("\t\t\t***  4.Change     the  student's score4     ***\t\t\t\n");
     printf("\t\t\t***  5.Change     the  student's score5     ***\t\t\t\n");
     printf("Please input i=:\n");
     scanf("%d",&i);
     switch (i)
      { case 1:printf("Please input the student's score1:\n");
              scanf("%f",&p);
              stu[k].s[0]=p;
              print(stu,k);break;
        case 2:printf("Please input the student's score2:\n");
              scanf("%f",&p);
              stu[k].s[1]=p;
              print(stu,k);break;
        case 3:printf("Please input the student's score3:\n");
              scanf("%f",&p);
              stu[k].s[2]=p;
           print(stu,k);break;
        case 4:printf("Please input the student's score4:\n");
              scanf("%f",&p);
              stu[k].s[3]=p;
             print(stu,k);break;
        case 5:printf("Please input the student's score5:\n");
              scanf("%f",&p);
              stu[k].s[4]=p;
              print(stu,k);break;
      }}while (i!=0);
      printf("please wait input any key continue");
      getch();
    }
void Delete (struct student stu[ ],int i)
{ long int m;
   printf("Please input the student's number=:\n");
   scanf("%ld",&m);
   for(i=0;i<N;i++)
   { 
       if (stu[i].number==m)
           stu[i]=stu[i+1]; 
    }
        print(stu,i);   
}

void Inquire(struct student stu[ ],int i)
{ long int m;
   printf("Please input the student's number=:\n");
   scanf("%ld",&m);
   for(i=0;i<N;i++)
   {  if (stu[i].number==m)
      { print(stu,i);
       }
   }
   printf("please wait input any key continue");
   getch();
}
  void Sort(struct student stu[ ],int i)
  {int j;
   float a;
    for (i=0;i<N;i++)
     {for (j=0;j<5;j++)
       {a=0;
        a+=stu[i].s[j];
        stu[i].sum=a;
        print(stu,i);
        printf("%8.1f\n",stu[i].sum);
        }
      }
     for (i=0;i<N;i++)
      {for (j=0;j<N+1;j++)
        {if (stu[i].sum>stu[j].sum)
           {temp=stu[i];
            stu[i]=stu[j];
            stu[j]=temp;
            }
        }
        print(stu,i);
        printf("%8.1f\n",stu[i].sum);
       }
       printf("please wait input any key continue");
       getch();
   }
void Statistics(struct student stu[ ],int i)
{int j,m=0,b=0;
   for (i=0;i<3;i++)
     for (j=0;j<5;j++)
       {if(stu[i].s[j]<60)
           m+=1;
            printf("| number | name  |\n");
            printf("| %ld |%s|\n",stu[i].number,stu[i].name);
            break;}                                        //*遇到<60,结束本层循环*//
       printf("the student don't pass exam have:%d\n",m);
       printf("\n");
       for (i=0;i<3;i++)
           for (j=0;j<5;j++)
           {  if (stu[i].s[j]>80)
               {b+=1;
                printf("||number||name||\n");
                printf("||%ld||%s||\n",stu[i].number,stu[i].name);
                break;}                                    //*遇到>80,结束本层循环*//
              
           }
           printf("the student  pass exam have:%d\n",b);
}



main()
{  int select,i=0;

    printf("\t\t\t***--------------------------------------------***\t\t\t\n");
    printf("\t\t\t***                                            ***\t\t\t\n");
    printf("\t\t\t***  Welcome to The Student's Mangement System ***\t\t\t\n");
    printf("\t\t\t***                                            ***\t\t\t\n");
    printf("\t\t\t***--------------------------------------------***\t\t\t\n");
    printf("\t\t\t***  1.Input      the  student's date          ***\t\t\t\n");
    printf("\t\t\t***  2.Search     the  student's date          ***\t\t\t\n");
    printf("\t\t\t***  3.Delete     the  student's date          ***\t\t\t\n");
    printf("\t\t\t***  4.Change     the  student's date          ***\t\t\t\n");
    printf("\t\t\t***  5.Inquire    the  student's date          ***\t\t\t\n");
    printf("\t\t\t***  6.Sort       the  student's date          ***\t\t\t\n");
    printf("\t\t\t***  7.Statistics the  student's date          ***\t\t\t\n");
    printf("\t\t\t***  0.Escape     the  student's system        ***\t\t\t\n");
    printf("Please input select=:\n");
    scanf("%d",&select);
      switch (select)
      {  case 1:Input(stu,i);break;
         case 2:Search(stu,i);break;
         case 3:Delete(stu,i);break;
         case 4:Change(stu,i);break;
         case 5:Inquire(stu,i);break;
         case 6:Sort(stu,i);break;
         case 7:Statistics(stu,i);break;
         default:printf("It's wrong");
       }

   
}

还有一个问题!调用Input后就释放数据了。???
望高手不吝赐教!!
2011-06-26 21:42
快速回复:能不能帮我看一下,这个哪里有出错吗?
数据加载中...
 
   



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

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