#include<stdio.h>




double ask(int param);

char ask();

char query();

double run(char opcode, double operand1, double opernad2);



int main(void)

{

double operand1, operand2, result;

    int plus = 0;

    int count = 0;

    char opcode, quit;

while(1)

{

    switch(plus)

    {


        case 0:

        operand1 = ask(++count);

        case 1:

        operand2 = ask(++count);

        opcode = ask();


        while(1)

        {

            if(opcode =='+'|| opcode == '-'|| opcode == '*'|| opcode == '/')

            {

                result = run(opcode, operand1, operand2);

                break;

            }


            else

            {

                printf("잘못된 연산기호 입니다. ");

                opcode = getchar();

            }

        }


        printf(" %lf %c %lf = %lf ", operand1, opcode, operand2, result);


        printf("추가 계산을하시겠습니까?(Y/n) ");

        getchar();

        plus = getchar();

        

        while(1)

        {

            if(plus == 'Y' || plus == 'y')

            {

                operand1 = result;

                plus = 1;

                break;

            }

            else if(plus == 'N' || plus == 'n')

            {

                printf(" 다시 하시겠습니까? (Y/n) ");

                getchar();

                quit = getchar();

                    while(1)

                    {

                        if(quit == 'N' || quit == 'n')

                        {

                            break;

                        }

                        else if(quit == 'Y' || quit == 'y')

                        {

                            operand1 = operand2 = result = 0;

                            plus = count = 0;

                            opcode = quit = 0;

                            break;

                        }

                        else

                        {

                            quit = query();

                        }

                    }

            break;

            }

            else

            {

                plus = query();

            }

        }

    }

break;

}

    printf("Bye :) ");

    return 0;

}


double ask(int param)

{

    double input;

    printf("%d번째 숫자를 입력해주십시오. ", param);

    scanf("%lf", &input);

    getchar();

    return input;

}


char ask()

{

    char input;

    printf("연산기호를 입력해 주십시오. ");

    input = getchar();

    return input;

}


char query()

{

    char input;

    printf("Y or N ");

    printf("다시 입력해 주십시오. ");

    input = getchar();

    return input;

}


double run(char opcode, double operand1, double operand2)

{

switch(opcode)

{

    case('+'):

        return operand1 += operand2;

        break;

    case('-'):

        return operand1 -= operand2;

        break;

    case('*'):

        return operand1 *= operand2;

        break;

    case('/'):

        return operand1 /= operand2;

}

}




근데 만약 y/n 같은 질문할때 2번씩뜨는데 이유를 모르겠어 


즉 


y/n 형에서 숫자 3을입력하면 보통 ("잘못된 입력입니다 ")이런식으로 한번떠야되는데 


("잘못된 입력입니다 ")

("잘못된 입력입니다 ")

이런식으로나와