minseo-jung / study-c

0 stars 0 forks source link

학점 계산기 만들기 #6

Closed minseo-jung closed 5 years ago

minseo-jung commented 5 years ago
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

void p8_1_3()
{
    int a, b, c, d;
    double e;
    printf("국어 점수를 입력하세요\n");
    scanf("%d", &a);
    printf("수학 점수를 입력하세요\n");
    scanf("%d", &b);
    printf("영어 점수를 입력하세요\n");
    scanf("%d", &c);

    d = a + b + c;
    e = (float)d / 3;

    if (e >= 90)
        printf("A입니다\n");
    else if (e >= 80)
        printf("B입니다\n");
    else if (e >= 70)
        printf("C입니다\n");
    else
        printf("F입니다");

    return 0;
}
minseo-jung commented 5 years ago

변형

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

void p8_1_4()
{
    int a, b, c, d;
    double e;
    char f=0;
    printf("국어 점수를 입력하세요\n");
    scanf("%d", &a);
    printf("수학 점수를 입력하세요\n");
    scanf("%d", &b);
    printf("영어 점수를 입력하세요\n");
    scanf("%d", &c);

    d = a + b + c;
    e = (float)d / 3;
    if (e >= 80)
    {
        f = (e >= 90) ? 'A' : 'B';
        printf("%c\n", f);
    }
        else if (e <= 80)
            f = (e >= 70) ? 'C' : 'F';
        printf("%c\n", f); 

}
wonny25 commented 5 years ago

변수명을 a, b, c, d, e이렇게 적었는데 프로그램이 복잡해지면 헷갈리게 될거야. 국어는 kor, 수학은 math, 영어는 eng, 평균은 avg 등으로 변수명을 적으면 무슨값이 들어갈 것인가에 대해 쉽게 이해할수 있을거야. 그리고 d를 형변환하는 (float)을 사용했는데 e = d / 3.;이라고도 써봐 어떤 일이 벌어지는지