IT_Programming/C · C++

[C] 구조체 배열_학생 성적 그래프

JJun ™ 2009. 6. 16. 16:26

[실행화면]

 

====================================================================================

 

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

 

#define SIZE       100

 

struct student

{

     int score;

     char name[100];

} std[3];

 

void print(int count);

char score(int score);

 

int main(void)

{

     int i = 0;

     while(i < 3)

     {

            printf("input the name and grade : ");

            scanf("%s %d", &std[i].name, &std[i].score);

            i++;

     }

     printf("\n");

 

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

     {

            printf("%+10s (%d) |%c| ",std[i].name, std[i].score, score(std[i].score));

            print(std[i].score / 10);

     }

     return 0;

}

 

void print(int count)

{

     int i;

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

     {

            printf("*");

     }

     printf("\n");

}

 

char score(int score)

{

     if(score >= 90 && score <= 100)

            return 'A';

     else if(score >= 80 && score < 90)

            return 'B';

     else if(score >= 70 && score < 80)

            return 'C';

     else if(score >= 60 && score < 70)

            return 'D';

     else if(score < 60)

            return 'F';

}

 

==================================================================================================