m0_56748399 2021-06-06 11:49 采纳率: 50%
浏览 15
已采纳

刚学习C语言,求大佬指点一下代码哪里有问题 求平均成绩的时候会出现错误

#include <stdio.h>

# define S 60.0

# define N 3

struct student 

{

 int n;

 char name[10];

 float score[3];

 float ave; 

}; 

int main ()

{

 void input (struct student stu[]);

 void bujige (struct student stu[]);

 void youxiu (struct student stu[]);

 struct student stu[N],*p=stu;

 input (p);

 bujige(p);

 youxiu (p);

 return 0; 

void input (struct student stu[])

{

 int i;

 printf ("请输入各学生的学号姓名及三门课成绩:\n");

 for (i=0;i<N;i++)

 {

  printf ("请输入第%d个学生信息:",i+1);

  scanf ("%d-%s-%f-%f-%f",&stu[i].n,&stu[i].name,&stu[i].score[0],&stu[i].score[1],&stu[i].score[2]);

  stu[i].ave=(stu[i].score[0]+stu[i].score[1]+stu[i].score[2])/3.0;

  printf ("\n");

  printf ("%f",stu[i].ave);

 } 

}

void bujige (struct student stu[])

{

 int i,j,k=0;

 for (i=0;i<N;i++)

 {

  for (j=0;j<3;j++)

  {

   if (stu[i].score[j]<S)

   k++; 

  }

  if (k>1)

  {

   printf ("\n");

   printf ("学号:%d",stu[i].n);

   for (j=0;j<3;j++)

   {

    if (stu[i].score[j]<S)

    printf ("不及格成绩:%f ",stu[i].score[j]);

   }

  } 

 } 

}

void youxiu (struct student stu[])

{

 int i;

 for (i=0;i<N;i++)

 {

  if (stu[i].ave>=85.0&&stu[i].ave<=90.0)

  printf ("学号:%d 姓名:%s",stu[i].n,stu[i].name);  

 }   

}

  • 写回答

3条回答 默认 最新

  • 关注

    scanf ("%d-%s-%f-%f-%f",&stu[i].n,&stu[i].name,&stu[i].score[0],&stu[i].score[1],&stu[i].score[2]);

    改为

    scanf ("%d-%s",&stu[i].n,&stu[i].name);

    fflush(stdin);

    scanf (%f-%f-%f",&stu[i].score[0],&stu[i].score[1],&stu[i].score[2]);

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件