편집 기록

편집 기록
  • 프로필 nowp님의 편집
    날짜2019.05.13

    c언어에서 getchar가 작동하지 않습니다.


    #include <stdio.h>
    
    float sum(float, float);
    float dif(float, float);
    float mul(float, float);
    float div(float, float);
    
    float sum(float x, float y)
    {
        return x+y;
    }
    
    float dif(float x, float y)
    {
        return x-y;
    }
    
    float mul(float x, float y)
    {
        return x*y;
    }
    
    float div(float x, float y)
    {
        return x/y;
    }
    
    int main(void)
    {
        float x, y;
        printf("두 실수를 입력해주세요");
        scanf("%f %f", &x, &y);
    
        printf("두 실수의 합: + \n");
        printf("두 실수의 차: - \n");
        printf("두 실수의 곱: * \n");
        printf("두 실수의 나누기: / \n");
        printf("원하시는 기능을 선택해주세요");
        char op = getchar();  // <<<<<--------!!!!!!
    
        switch(op)
        {
            case '+': printf("합은 :%f", sum(x, y)); break;
            case '-': printf("차는: %f", dif(x, y)); break;
            case '*': printf("곱은: %f", mul(x, y)); break;
            case '/': printf("몫은: %f", div(x, y)); break;
        }   
        return 0;
    }
    

    char op = getchar()가 작동하지 않고 바로 종료됩니다. 어디가 문제인가요?

  • 프로필 조정현님의 편집
    날짜2019.04.15

    c언어에서 getchar가 작동하지 않습니다.


    include

    float sum(float, float); float dif(float, float); float mul(float, float); float div(float, float);

    float sum(float x, float y) { return x+y; }

    float dif(float x, float y) { return x-y; }

    float mul(float x, float y) { return x*y; }

    float div(float x, float y) { return x/y; }

    int main(void) { float x, y; printf("두 실수를 입력해주세요"); scanf("%f %f", &x, &y);

    printf("두 실수의 합: + \n");
    printf("두 실수의 차: - \n");
    printf("두 실수의 곱: * \n");
    printf("두 실수의 나누기: / \n");
    printf("원하시는 기능을 선택해주세요");
    **char op = getchar();**
    
    switch(op)
    {
        case '+': printf("합은 :%f", sum(x, y)); break;
        case '-': printf("차는: %f", dif(x, y)); break;
        case '*': printf("곱은: %f", mul(x, y)); break;
        case '/': printf("몫은: %f", div(x, y)); break;
    }   
    return 0;
    

    }

    char op = getchar()가 작동하지 않고 바로 종료됩니다. 어디가 문제인가요?