| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 349 人关注过本帖
标题:新手自己编的,求高手改正
只看楼主 加入收藏
Struggle丶
Rank: 1
等 级:新手上路
帖 子:8
专家分:5
注 册:2010-12-11
结帖率:50%
收藏
已结贴  问题点数:10 回复次数:3 
新手自己编的,求高手改正
#include<stdio.h>
#include<stdlib.h>
#define N 10
struct
{
  int   num ;
  char  name[N];
  int   waiyu;
  int   shuxue;
  int   diannao;  
}stu[20]={{20100,"aa",88,92,86},\     /***初始化结构体数组***/
          {20101,"bb",58,69,75},\
          {20102,"cc",55,73,80},\
          {20103,"dd",58,63,57},\
          {20104,"ee",78,80,45},\
          {20105,"ff",89,69,75},\
          {20106,"gg",57,87,65},\
          {20107,"hh",88,89,95},\
          {20108,"ii",77,46,67},\
          {20109,"jj",85,75,68}};
void funct1();                        /***函数声明***/
void funct2();
void funct3();
void funct4();

int main()
{
    int i;
    char choice;
 printf(" \n ercorde name \t \t num\t\twaiyu \tshuxue\tdiannao\n");
for(i=0;i<=N-1;i++)                                   /***结构体数组输出***/
 printf(" %d\t%-18s%-9d%10d\t%3d\t%6d\n",i,stu[i].name,stu[i].num,stu[i].waiyu,stu[i].shuxue,stu[i].diannao);
 printf("      ===the informination of student===\n");
 printf("      -------------------------------------------------------------\n");
 printf("\n");
 printf("      1.the avarage of the student         3.stdudent's  rank\n");
 printf("\n");
 printf("      2.the avarage of the class           4.the name who fail\n");
 printf("\n");
 printf("                  0.exc\n   ");
 printf("\n");
 printf("   -------------------------------------------------------------\n");
 printf("choice the number(0-4):\n");                      /***显示菜单***/
 
 printf("please choice:");
  do
 {   
    choice=getchar();
    switch(choice)
  {
  case'1': funct1(); break;                                /***由输入确定调出函数***/
  case'2': funct2(); break;
  case'3': funct3(); break;
  case'4': funct4(); break;
  case'0': exit(0);
  }
 }while(choice);

  return 0;
}  



void funct1()
{
    int m,n,temp,i,b[3]={0,0,0},sum[3]={0,0,0};
{
  for(i=0;i<N;i++)
  {
  sum[i]=stu[i].waiyu+stu[i].shuxue+stu[i].diannao;              /***由数组sum【】存放每个学生的总成绩***/

  b[i]=sum[i]/3.0;                                               /***由数组b【】存放每个学生的平均成绩***/
      printf("the %d'sum is %3d                     the %d'avarage is %3d\n",stu[i].num,sum[i],i,b[i]);        /***输出学生的总成绩和平均成绩***/

 }
{
   for(n=0;n<=N-2;n++)                                            /***比较学生的平均并输出***/
    for(i=0;i<N-n-1;i++)
     if(b[i]<b[i+1])
    {temp=b[i];b[i]=b[i+1];b[i+1]=temp;}
 for(i=0;i<=N-1;i++)
printf("                     the  avarage %d is the rank  %d\n",b[i],i+1);
}  

}

}


void funct2()
{
    int i,b[N]={0,0,0},sum[N]={0,0,0},m1=0,m2=0,m3=0,m4=0,c;
  for(i=0;i<N;i++)
  {
  sum[i]=stu[i].waiyu+stu[i].shuxue+stu[i].diannao;              
 
  b[i]=sum[i]/3.0;                                               /***算出每个学生的平均成绩***/
      printf("     the %d'avarage is %3d\n",stu[i].num,b[i]);

 }
 
  for(i=0;i<N;i++)                                             
  {
      c=b[i]/10;
switch(c)                                                           /***确定每个分数段的人数***/
 {
  case 1:
  case 2:
  case 3:
  case 4:
  case 5: m1=m1+1;  break;
  case 6:
  case 7: m2=m2+1;  break;
  case 8: m3=m3+1;  break;
  case 9:
  case 10:m4=m4+1;  break;
 }
  }   
  printf("below 60:%d  60-79:%d  80-89:%d  above90:%d",m1,m2,m3,m4);            /***输出每个分数段的人数***/
}

void funct3()
  {
    int i,num;
  printf("please the number of the student:");
  scanf("%d",&num);
  printf("\n ercorde name \t \t num\t\twaiyu \tshuxue\tdiannao\n");                   /***输出表头***/
  for (i=0;i<N;i++)
   {   
  if (num==stu[i].num)                                                                  /***检索***/   
   {
   printf ("%d\t%-18s%-9d%10d\t%3d\t%6d\n",i,stu[i].name,stu[i].num,stu[i].waiyu,stu[i].shuxue,stu[i].diannao);   /***输出检索结果***/

  }
}
}
void funct4()
{
int i;
 printf ("the name of waiyu fail:");                                                                       /***输出英语成绩***/
for(i=0;i<N;i++)
{
    if(stu[i].waiyu<60)                                                                   /***进行比较***/      
      printf ( "%s\n",stu[i].name);                                                        /***输出成绩不及格人数***/
}      
printf ("the name of shuxue fail:");
for(i=0;i<N;i++)
{                                                                                         /***输出数学成绩***/
    if(stu[i].shuxue<60)                                                                  /***进行比较***/
    printf (" %s\n",stu[i].name);                                                         /***输出成绩不及格人数***/                           
}   
   
printf ("the name of diannao fail:");
for(i=0;i<N;i++)                                                                           /***输出电脑成绩***/
{
    if(stu[i].diannao<60)                                                                  /***进行比较***/
    printf ("%s\n",stu[i].name);                                                           /***输出成绩不及格人数***/      
}
         
}


自己编的,想在菜单下工作。求高手指点  为什么输入 1  ,不能返回菜单。   
搜索更多相关主题的帖子: 结构体 
2010-12-30 11:30
qq1023569223
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:湖南科技大学
等 级:贵宾
威 望:26
帖 子:2753
专家分:13404
注 册:2010-12-22
收藏
得分:7 
void funct1()
{
    int m,n,temp,i,b[N]={0},sum[N]={0};
{
  for(i=0;i<N;i++)
  {
  sum[i]=stu[i].waiyu+stu[i].shuxue+stu[i].diannao;            
  b[i]=sum[i]/3.0;                                             
  printf(  "the %d sum is %3d ,the %d avarage is %3d\n",stu[i].num,sum[i],i,b[i]); }
  }
   for(n=0;n<=N-2;n++)                                            /***比较学生的平均并输出***/
    for(i=0;i<N-n-1;i++)
     if(b[i]<b[i+1])
    {temp=b[i];b[i]=b[i+1];b[i+1]=temp;}
 for(i=0;i<=N-1;i++)
 printf(" the  avarage %d is the rank  %d\n",b[i],i+1);
  }
}


void funct2()
{
    int i,b[N]={0},sum[N]={0},m1=0,m2=0,m3=0,m4=0,c;
    for(i=0;i<N;i++)
  {
   sum[i]=stu[i].waiyu+stu[i].shuxue+stu[i].diannao;              
   b[i]=sum[i]/3.0;                                               /***算出每个学生的平均成绩***/
   printf("he %d'avarage is %3d\n",stu[i].num,b[i]);
}

  for(i=0;i<N;i++)                                             
  {
      c=b[i]/10;
     switch(c)                                                           /***确定每个分数段的人数***/
  {
  case 1:
  case 2:
  case 3:
  case 4:
  case 5: m1=m1+1;  break;
  case 6:
  case 7: m2=m2+1;  break;
  case 8: m3=m3+1;  break;
  case 9:
  case 10:m4=m4+1;  break;
 }
  }   
  printf("below 60:%d  60-79:%d  80-89:%d  above90:%d",m1,m2,m3,m4);            /***输出每个分数段的人数***/
}


   唯实惟新 至诚致志
2010-12-30 13:50
qq1023569223
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:湖南科技大学
等 级:贵宾
威 望:26
帖 子:2753
专家分:13404
注 册:2010-12-22
收藏
得分:3 
struct
{
  int   num ;
  char  name[N];
  int   waiyu;
  int   shuxue;
  int   diannao;  
}stu[N]={{20100,"aa",88,92,86},   
          {20101,"bb",58,69,75},
          {20102,"cc",55,73,80},
          {20103,"dd",58,63,57},
          {20104,"ee",78,80,45},
          {20105,"ff",89,69,75},
          {20106,"gg",57,87,65},
          {20107,"hh",88,89,95},
          {20108,"ii",77,46,67},
          {20109,"jj",85,75,68}};

   唯实惟新 至诚致志
2010-12-30 13:52
Struggle丶
Rank: 1
等 级:新手上路
帖 子:8
专家分:5
注 册:2010-12-11
收藏
得分:0 
谢谢, 谢谢。。 搞定了  。。
  但能不能告诉我,  原来我错呢了?
2010-12-30 15:01
快速回复:新手自己编的,求高手改正
数据加载中...
 
   



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

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