카테고리 없음

성적프로그램(2)

Ohmaigoodz 2019. 12. 5. 16:07

표준 입력으로 학번 구간을 입력 받아 그 학번들을 포함하는 구간내에 해당하는 학생들의 성적을 출력

 

 

#include <stdio.h>

#include <stdlib.h>    // atoi 함수가 선언된 헤더 파일

 

 

 

typedef struct

{

    char stuNum[30];

    char name[30];

    float Kor;

    float Eng;

    float Math;

    float total;

    float ave;

    

}Student;

 

 

int main()

{

    Student arr[3] = {0,};//구조체

    

    float totK=0;

    float totE=0;

    float totM=0;

    float totA=0;

    

    int sNum;//처음 학번

    int lNum; //끝 학번

    int stuNum; //atoi용

    int count = 0;

    

    for(int i = 0; i<3; i++){

        scanf("%s%s%f%f%f",arr[i].stuNum,arr[i].name,&arr[i].Kor,&arr[i].Eng,&arr[i].Math);

        arr[i].total = arr[i].Kor+arr[i].Eng+arr[i].Math;

               arr[i].ave = arr[i].total/3;

    }

    

    printf("학번 구간을 입력하시오: ");

    scanf("%d%d",&sNum,&lNum);

    

    if(sNum && lNum == 0)

    {

        exit(0);

    }

    else if(sNum || lNum !=0)

    {

  

     printf("학번      이름   국어   영어   수학  총점   평균\n");

    

    for(int i = 0; i<3; i++){

        

       stuNum =  atoi(arr[i].stuNum);

        if((stuNum >=sNum) && (stuNum <= lNum)){

        printf("%3s %3s %3.f %3.f %3.f %5.f %5.1f\n",arr[i].stuNum,arr[i].name,arr[i].Kor,arr[i].Eng,arr[i].Math,arr[i].total,arr[i].ave);

            count++;

            totK+=arr[i].Kor;

            totE+=arr[i].Eng;

            totM+=arr[i].Math;

        }

    }

    

   

    totA = (totK/count+totE/count+totM/count)/3;

    

    printf("=========================================\n");

    printf("전체 평균           %3.1f %3.1f %3.1f %6.1f\n",totK/count,totE/count,totM/count,totA);

        

    

    }

    return 0;

}