计算人数低于60的人

时间:2019-05-03 07:38:23

标签: c

计算多少个分数低于60的人,然后打印结果。

代码:

struct student{
  char id[10];
  char fname[25];
  char lname[25];
  char letter[10];
  int quiz[4];
  int assignment[4];
  int project,MID,Final,grade,percentage,average,sum,fail;
};

int main(int argc, char const *argv[]) {
  struct student person[10];
  int input,choose,temp;

  printf("Input Student : ");
  scanf("%d",&input );
  printf("\n");

  int i,j,k,h,l;
  for ( i = 0; i < input; i++) {
    int count=0,count2=0;
    fail=0;
    printf("Input Id : ");
    scanf("%s",person[i].id);
    printf("Input Name : ");
    scanf("%s",person[i].fname);
    scanf("%s",person[i].lname);
    printf("\n");

    //input assignment
    for ( j = 0; j < 3; j++) {
      printf("Input Assignment%d : ",j );
      scanf("%d",&person[j].assignment[i] );
      count+=person[j].assignment[i];
      person[i].average = count/3;
    }
    person[i].percentage = person[i].average*0.20;

    printf("\n");
    //input quiz
    for ( k = 0; k < 4; k++) {
      printf("Input Quiz%d : ",k );
      scanf("%d",&person[k].quiz[i] );
      count2+=person[k].quiz[i];
      person[i].average = count2/4;
    }
    person[i].sum = person[i].average*0.10;
    printf("\n");

    //input Project
    printf("Input Project Value%d : ",i );
    scanf("%d",&person[i].project );
    person[i].project= person[i].project * 0.15;
    printf("\n");

    //input MID
    printf("Input Project Value%d : ",i );
    scanf("%d",&person[i].MID );
    fflush(stdin);
    person[i].MID= person[i].MID * 0.25;
    printf("\n");

    //input Final
    printf("Input Project Value%d : ",i );
    scanf("%d",&person[i].Final );
    fflush(stdin);
    person[i].Final= person[i].Final * 0.25;

    //count Grade
    person[i].grade = person[i].percentage + person[i].sum + person[i].project + person[i].MID + person[i].Final;

    printf("\n");

    person[i].fail = person[0].grade;
    for ( l = 0; l < input; l++) {
      if (person[l].grade < 60) {
        person[i].fail++;
      }
    }
  }
  • 我希望输出是这样的。
    • 如果超过三个人的分数小于60,则会打印“三个人的分数较低”或“不及格”。
    • 如果三个人的分数超过60,则“ 3人通过”。

这是完整的源代码: https://github.com/PrinceSP/compro-1/blob/master/compro2/Structure/Exercise2.c

1 个答案:

答案 0 :(得分:1)

在此代码中,main永远不会结束,因此无法编译,请检查一下,然后为我们提供有关您的问题的更多信息