| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 448 人关注过本帖
标题:求高手调试,找找有什么问题!
只看楼主 加入收藏
狼治天下
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2011-6-19
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:8 
求高手调试,找找有什么问题!
/*  HELLO.C -- Hello, world */

#include "stdio.h"
#include "conio.h"
#include "math.h"
struct a
{
    int xh;
    char xm[10];
    int qz;
    int qm;
    int zp;
};
/*定义数组*/
int add(struct a z[50],int i)
{
    int a,b;
    printf("add number\n");
    scanf("%d",&a);
    for(b=1;b<=a;b++)
    {printf("xh xm qz qm \n");
    scanf("%d %s %d %d",&z[b].xh,&z[b].xm,&z[b].qz,&z[b].qm);
    z[b].zp=z[b].qz+z[b].qm;
    }
    i=i+1;
    return i;
}
/*添加记录*/
int delete(struct a z[50],int i)
{
    int j,k,l;
    printf("delete xh");
    scanf("%d",&k);
    for(j=0;j<=i;j++)
      if(k==z[j].xh)
        l=j;
    for(;l<=i;l++)
      z[l]=z[l+1];
    i--;
    return i;
}
/*删除记录*/
void sort(struct a z[50],int i)
{
    int j,k;
    struct a a;
    for(j=0;j<i;j++)
      for(k=j+1;k<=i;k++)
        if(z[j].zp>z[k].zp)
        {
           a=z[j];
           z[j]=z[k];
           z[k]=a;
        }
}
/*记录排序*/
int top(struct a z[50],int i)
{
  int j,k,max=0;
  for(j=0;j<=i;j++)
    if(z[j].zp>max)
      max=z[j].zp;

  printf("the top is %d",max);

}
/*最高分*/
int low(struct a z[50],int i)
{
  int j,k,min;
  for(j=0;j<=i;j++)
    if(z[j].zp<z[j+1].zp)
      min=z[j].zp;
    else
      min=z[j+1].zp;
  printf("the low is %d",min);
}
/*最低分*/
int  ave(struct a z[50],int i)
{ int j,s=0;
  for(j=0;j<=i;j++)
    {
       s=s+z[j].zp;

    }

  printf("the average is%d",s/i);

}
/*平均分*/
void pass(struct a  z[50],int i)
{
  int j,k;
  for(j=0;j<=i;j++)
   {
     if(z[j].zp>=60)
      k++;

   }
   return k;
}
/*及格率*/
void  name(struct a z[50],int i)
 {  int j,k;
    printf("please input name:");
    scanf("%s",&k);
    for(j=0;j<=i;j++)
      {
        if(z[j].xm==k)
           printf("%d %s %d %d %d",z[j].xh,z[j].xm,z[j].qz,z[j].qm,
           z[j].zp=z[j].qz*0.3+z[j].qm*0.7);
        else
           printf("error!") ;

      }

 }

 /*按姓名查询*/
void number(struct a z[50],int i)
 {  int j,k;
    printf("please input number:");
    scanf("%d",&k);
    for(j=0;j<=i;j++)
      {
        if(z[j].xh==k)
           printf("%d %s %d %d %d",z[j].xh,z[j].xm,z[j].qz,z[j].qm,
           z[j].zp=z[j].qz*0.3+z[j].qm*0.7);
        else
           printf("error!") ;

      }

 }
 /*按学号查询*/
main()
{   struct a z[50];
    int a,b,i;
    char c,w;




    printf("********************************************************************************");
    printf("\n");
    printf("                               1.Grade Management                               ");
    printf("\n");
    printf("                               2.Results Summary                                ");
    printf("\n");
    printf("                               3.Search Results                                 ");
    printf("********************************************************************************");

    printf("\n\n");
    printf("                           qing xuan ze:");
    printf("\n\n\n");
    printf("qing xuan ze  :  ");
    scanf("%d",&a);
    if(a==1)
     { clrscr();
       printf("                          ****************************\n\n");
       printf("***************************    1.Grade Management    ***************************\n");
       printf("                          ****************************\n\n");
       printf("\n\n\n\n");
       printf("%s\n\n\n","                               1. Add stu_info");
       printf("%s\n\n\n","                               2. Delete stu_info");
       printf("%s\n\n\n","                               3. Sort stu_info");
       printf("%s\n\n\n","                               4. return");
       printf("qing xuan ze :  ");
       getchar();
       scanf("%c",&b);
       if(b==1)
          i=add(&z,i);
       if(b==2)
          i=delete(&z,i);
       if(b==3)
           sort(&z,i);
       getchar();
         
      }
     if(a==2)
       { clrscr();
       printf("                          ****************************\n\n");
       printf("***************************    2.Results Summary     ***************************\n");
       printf("                          ****************************\n\n");
       printf("\n\n\n\n");
       printf("%s\n\n\n","                               1. Check top grade");
       printf("%s\n\n\n","                               2. Check low grade");
       printf("%s\n\n\n","                               3. Check all the average grade");
       printf("%s\n\n\n","                               4. Check the pass grade");
       printf("%s\n\n\n","                               5. return");
       printf("qing xuan ze  :  ");
       getchar();
       scanf("%c",&b);
       if(b==1)
        i=top(&z,i);
       if(b==2)
        i=low(&z,i);
       if(b==3)
        i=ave(&z,i);
       if(b==4)
       pass(&z,i);
       getchar();
      }
     if(a==3)
     { clrscr();
       printf("                          ****************************\n\n");
       printf("***************************    3.Search Results      ***************************\n");
       printf("                          ****************************\n\n");
       printf("\n\n\n\n");
       printf("%s\n\n\n","                               1. Check the grade by name");

       printf("%s\n\n\n","                               2. Check the grade by number");
       printf("%s\n\n\n","                               3. return");
       printf("qing xuan ze  :  ");
       getchar();
       scanf("%c",&b);
       if(b==1)
        name(&z,i);
       if(b==2)
        number(&z,i);
       getchar();


      }



}

搜索更多相关主题的帖子: 记录 include number return world 
2011-06-20 21:12
pkwangxinjun
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:45
专家分:170
注 册:2010-8-29
收藏
得分:7 
这程序写的惨不忍睹
2011-06-20 22:25
gao_guai
Rank: 2
等 级:论坛游民
帖 子:73
专家分:16
注 册:2011-6-5
收藏
得分:7 
将clrscr();去掉 clrscr()是TC特有的

2011-06-20 22:32
狼治天下
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2011-6-19
收藏
得分:0 
/*  HELLO.C -- Hello, world */

#include "stdio.h"       /*最低分和按姓名查找不对*/
#include "conio.h"
#include "math.h"
struct a
{
    int xh;
    char xm[10];
    int qz;
    int qm;
    int zp;
};
/*定义数组*/
int add(struct a z[50],int i)
{
    int a,b;
    printf("input number\n");
    scanf("%d",&a);
    for(b=1;b<=a;b++)
    {printf("xuehao xingming qizhong qimo\n");
    scanf("%d %s%d %d",&z[i+b].xh,&z[i+b].xm,&z[i+b].qz,&z[i+b].qm);
    z[i+b].zp=z[i+b].qz*0.3+z[i+b].qm*0.7;}
    i=i+a;
    return i;
}
/*添加记录*/
int delete(struct a z[50],int i)
{
    int j,k,l;
    printf("delete xh");
    scanf("%d",&k);
    for(j=0;j<=i;j++)
      if(k==z[j].xh)
        l=j;
    for(;l<=i;l++)
      z[l]=z[l+1];
    i--;
    return i;
}
/*删除记录*/
void sort(struct a z[50],int i)
{
    int j,k;
    struct a a;
    for(j=0;j<i;j++)
      for(k=j+1;k<=i;k++)
        if(z[j].zp>z[k].zp)
        {
           a=z[j];
           z[j]=z[k];
           z[k]=a;
        }
}
/*记录排序*/
void top(struct a z[50],int i)
{
  int j,k;
  for(j=0;j<=i;j++)
    if(z[j].zp>z[0].zp)
      z[0].zp=z[j].zp;
}
/*最高分*/
void low(struct a z[50],int i)
{
  int j,k;
  z[0].zp=z[1].zp;
  for(j=2;j<=i;j++)
    if(z[j].zp<z[0].zp)
      z[0].zp=z[j].zp;

}
/*最低分*/
void ave(struct a z[50],int i)
{ int j;
  for(j=1;j<=i;j++)
    {
     z[0].zp=z[0].zp+z[j].zp;

    }

    z[0].zp=z[0].zp/i;

}
/*平均分*/
float pass(struct a  z[50],int i)
{
  int j;
  float k=0;
  for(j=1;j<=i;j++)
   {
     if(z[j].zp>=60)
      k++;

   }
   return k;
}
/*及格率*/
void  name(struct a z[50],int i)
 {  int j,l=0;
    char k[10];
    printf("please input name:");
    scanf("%s",&k);
    for(j=0;j<=i;j++)
      {
        if(z[j].xm==k)
           printf("%d %s %d %d %d",z[j].xh,z[j].xm,z[j].qz,z[j].qm,z[j].zp);
         l=1;
      }
       if(l==0)
      printf("error!") ;
 }

 /*按姓名查询*/
void number(struct a z[50],int i)
 {  int j,k,l=0;
    printf("please input number:");
    scanf("%d",&k);
    for(j=1;j<=i;j++)
      {
        if(z[j].xh==k)
           printf("%d %s %d %d %d",z[j].xh,z[j].xm,z[j].qz,z[j].qm,z[j].zp);
         l=1;
      }
       if(l==0)
      printf("error!") ;

 }
 /*按学号查询*/
main()
{   struct a z[50]={{0}};
    int a,b,i=0;
    float d;
    char c,w;


    do{



    printf("********************************************************************************");
    printf("\n");
    printf("                               1.Grade Management                               ");
    printf("\n");
    printf("                               2.Results Summary                                ");
    printf("\n");
    printf("                               3.Search Results                                 ");
    printf("********************************************************************************");
    printf("\n\n");
    printf("                           qing xuan ze:");
    printf("\n\n\n");
    printf("qing xuan ze  :  ");
    scanf("%d",&a);
    if(a==1)
     {
       printf("                          ****************************\n\n");
       printf("***************************    1.Grade Management    ***************************\n");
       printf("                          ****************************\n\n");
       printf("\n\n\n\n");
       printf("%s\n\n\n","                               1. Add stu_info");
       printf("%s\n\n\n","                               2. Delete stu_info");
       printf("%s\n\n\n","                               3. Sort stu_info");
       printf("%s\n\n\n","                               4. return");
       printf("qing xuan ze :  ");

          scanf("%d",&b);
          if(b==1)
            i=add(&z,i);
          if(b==2)
            i=delete(&z,i);
          if(b==3)
            sort(&z,i);
      }
     if(a==2)
       {
       printf("                          ****************************\n\n");
       printf("***************************    2.Results Summary     ***************************\n");
       printf("                          ****************************\n\n");
       printf("\n\n\n\n");
       printf("%s\n\n\n","                               1. Check top grade");
       printf("%s\n\n\n","                               2. Check low grade");
       printf("%s\n\n\n","                               3. Check all the average grade");
       printf("%s\n\n\n","                               4. Check the pass grade");
       printf("%s\n\n\n","                               5. return");
       printf("qing xuan ze  :  ");
       scanf("%d",&b);
       if(b==1)
       { top(&z,i);
       printf("%d\n",z[0].zp);}
       if(b==2)
        {low(&z,i);
       printf("%d\n",z[0].zp);}
       if(b==3)
        {ave(&z,i);
       printf("%d\n",z[0].zp);}
       if(b==4)
       {d=pass(&z,i);
       d=d/i;
       printf("%f\n",d);
       }}
     if(a==3)
     { clrscr();
       printf("                          ****************************\n\n");
       printf("***************************    3.Search Results      ***************************\n");
       printf("                          ****************************\n\n");
       printf("\n\n\n\n");
       printf("%s\n\n\n","                               1. Check the grade by name");

       printf("%s\n\n\n","                               2. Check the grade by number");
       printf("%s\n\n\n","                               3. return");
       printf("qing xuan ze  :  ");
       scanf("%d",&b);
       if(b==1)
        name(&z,i);
       if(b==2)
        number(&z,i);


      }

  /*        for(a=1;a<=i;a++)
      printf("%d %s %d %d %d\n",z[a].xh,z[a].xm,z[a].qz,z[a].qm,z[a].zp);
   */
    printf("shi fou ji xu:(y or n )\n");
    scanf("%s",&c);
    }while(c=='y'||c=='Y');
      getch();
}
这是第二次修改的,就还有两处地方修改不对......
2011-06-20 23:05
狼治天下
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2011-6-19
收藏
得分:0 
回复 2楼 pkwangxinjun
刚修改了半天,还是有不对的地方,能否解决,谢谢
2011-06-20 23:06
狼治天下
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2011-6-19
收藏
得分:0 
回复 3楼 gao_guai
就是用Tc写的程序
2011-06-20 23:07
ppfly
Rank: 10Rank: 10Rank: 10
等 级:青峰侠
帖 子:297
专家分:1956
注 册:2009-5-17
收藏
得分:7 
错误很多,基本语句不熟练。
主要的有函数的调用参数不对,变量的定义类型混乱,函数的定义混乱,返回值混乱,代码注释混乱(第一次看到注释再大段语句下面)。。。。。。
下面的是经修改的额可以运行的代码,很多细节自己慢慢找,体会。(部分函数没有结束表示,比如add函数,怎么判断add的结束?。。。)
程序代码:
/*  HELLO.C -- Hello, world */

#include "stdio.h"
#include "conio.h"
#include "math.h"
#include<stdlib.h>
struct a
{
    int xh;
    char xm[10];
    int qz;
    int qm;
    int zp;
};
/*定义数组*/
int add(struct a z[50],int i)
{
    int a,b;
    printf("add number\n");
    scanf("%d",&a);
    for(b=1;b<=a;b++)
    {
        printf("xh xm qz qm \n");
        scanf("%d %s %d %d",&z[b].xh,&z[b].xm,&z[b].qz,&z[b].qm);
        z[b].zp=z[b].qz+z[b].qm;
    }
    i=i+1;
    return i;
}
/*添加记录*/
int del(struct a z[50],int i)
{
    int j,k,l;
    printf("delete xh");
    scanf("%d",&k);
    for(j=0;j<=i;j++)
        if(k==z[j].xh)
            l=j;
        for(;l<=i;l++)
            z[l]=z[l+1];
    i--;
    return i;
}
/*删除记录*/
void sort(struct a z[50],int i)
{
    int j,k;
    struct a a;
    for(j=0;j<i;j++)
        for(k=j+1;k<=i;k++)
            if(z[j].zp>z[k].zp)
            {
                a=z[j];
                z[j]=z[k];
                z[k]=a;
            }
}
/*记录排序*/
int top(struct a z[50],int i)
{
    int j,k,max=0;
    for(j=0;j<=i;j++)
        if(z[j].zp>max)
            max=z[j].zp;
    //printf("the top is %d",max);
    return max;
}
/*最高分*/
int low(struct a z[50],int i)
{
    int j,k,min;
    for(j=0;j<=i;j++)
        if(z[j].zp<z[j+1].zp)
            min=z[j].zp;
        else
            min=z[j+1].zp;
        //printf("the low is %d",min);
    return min;
}
/*最低分*/
int  ave(struct a z[50],int i)
{
    int j,s=0;
    for(j=0;j<=i;j++)
    {
        s=s+z[j].zp;
    }
    //printf("the average is%d",s/i);
    return s/i;//注意这里s,i都是int型数据,所以s/i结果仍然是int型,不精确,建议将他们都改为float
}
/*平均分*/
int pass(struct a  z[50],int i)//////////既然有返回值,函数怎么能是void,改成int
{
    int j,k;
    for(j=0;j<=i;j++)
    {
        if(z[j].zp>=60)
            k++;
    }
    return k;
}
/*及格率*/
void  name(struct a z[50],int i)
{ 
    int j;
    char k[50];//k是字符串,怎么能定义为int型??????
    printf("please input name:");
    scanf("%s",&k);
    for(j=0;j<=i;j++)
    {
        if(z[j].xm==k)
            printf("%d %s %d %d %d",z[j].xh,z[j].xm,z[j].qz,z[j].qm,
            z[j].zp=z[j].qz*0.3+z[j].qm*0.7);
        else
            printf("error!") ;
    }
}
/*按姓名查询*/
void number(struct a z[50],int i)
{ 
    int j,k;
    printf("please input number:");
    scanf("%d",&k);
    for(j=0;j<=i;j++)
    {
        if(z[j].xh==k)
            printf("%d %s %d %d %d",z[j].xh,z[j].xm,z[j].qz,z[j].qm,
            z[j].zp=z[j].qz*0.3+z[j].qm*0.7);
        else
            printf("error!") ;
    }
}
/*按学号查询*/
int main()
{   struct a z[50];
    int a,b,i;
    char c,w;
    printf("********************************************************************************");
    printf("\n");
    printf("                               1.Grade Management                               ");
    printf("\n");
    printf("                               2.Results Summary                                ");
    printf("\n");
    printf("                               3.Search Results                                 ");
    printf("********************************************************************************");

    printf("\n\n");
    printf("                           qing xuan ze:");
    printf("\n\n\n");
    printf("qing xuan ze  :  ");
    scanf("%d",&a);
    if(a==1)
    { //clrscr();这是TC里的库函数,造就不适应新的WIn下的编译器,改成下面的语句,加上头文件stdlib.h
        system("CLS");
        printf("                          ****************************\n\n");
        printf("***************************    1.Grade Management    ***************************\n");
        printf("                          ****************************\n\n");
        printf("\n\n\n\n");
        printf("%s\n\n\n","                               1. Add stu_info");
        printf("%s\n\n\n","                               2. Delete stu_info");
        printf("%s\n\n\n","                               3. Sort stu_info");
        printf("%s\n\n\n","                               4. return");
        printf("qing xuan ze :  ");
        getchar();
        scanf("%d",&b);//%c??%c???这里b是一个整数,怎么能是%c呢,。。。。。。。。。
        if(b==1)
        i=add(z,i);/////注意这些函数的调用全部有错,去掉&符号,仔细看看你是怎么定义的,下同
        if(b==2)
        i=del(z,i);
        if(b==3)
        sort(z,i);
        getchar();
    }
    if(a==2)
    {
        //clrscr();
        system("CLS");
        printf("                          ****************************\n\n");
        printf("***************************    2.Results Summary     ***************************\n");
        printf("                          ****************************\n\n");
        printf("\n\n\n\n");
        printf("%s\n\n\n","                               1. Check top grade");
        printf("%s\n\n\n","                               2. Check low grade");
        printf("%s\n\n\n","                               3. Check all the average grade");
        printf("%s\n\n\n","                               4. Check the pass grade");
        printf("%s\n\n\n","                               5. return");
        printf("qing xuan ze  :  ");
        getchar();
        scanf("%c",&b);
        if(b==1)
        i=top(z,i);
        if(b==2)
        i=low(z,i);
        if(b==3)
        i=ave(z,i);
        if(b==4)
        pass(z,i);
        getchar();
    }
    if(a==3)
    {
        //clrscr();
        system("CLS");
        printf("                          ****************************\n\n");
        printf("***************************    3.Search Results      ***************************\n");
        printf("                          ****************************\n\n");
        printf("\n\n\n\n");
        printf("%s\n\n\n","                               1. Check the grade by name");
        printf("%s\n\n\n","                               2. Check the grade by number");
        printf("%s\n\n\n","                               3. return");
        printf("qing xuan ze  :  ");
        getchar();
        scanf("%c",&b);
        if(b==1)
        name(z,i);
        if(b==2)
        number(z,i);
        getchar();
    }
    return 0;
}

 

********多贴代码,少说空话*******
2011-06-22 15:40
狼治天下
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2011-6-19
收藏
得分:0 
回复 7楼 ppfly
恩,恩,一定。。。。谢谢
2011-06-23 22:18
sexywolfcrak
Rank: 2
等 级:论坛游民
帖 子:25
专家分:26
注 册:2011-6-13
收藏
得分:0 
楼主好强大,不错的帖子
2011-06-24 08:42
快速回复:求高手调试,找找有什么问题!
数据加载中...
 
   



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

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