#include<stdio.h>




double ask(int param);

char ask();

char query();

char solve();

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("잘못된 연산기호 입니다.\n");

                opcode = getchar();

            }

        }


        printf("\n\n%f %c %f = %f\n", operand1, opcode, operand2, result);


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

        plus = solve();

        

        while(1)

        {

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

            {

                operand1 = result;

                plus = 1;

                break;

            }

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

            {

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

                quit = solve();

                    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 :)\n");

    return 0;

}


double ask(int param)

{

    double input;

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

    scanf("%lf", &input);

    getchar();

    return input;

}


char ask()

{

    char input;

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

    input = getchar();

    return input;

}


char query()

{

    char input;

    printf("Y or N\n");

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

    input = getchar();

    return input;

}


char solve()

{

    char input;

    getchar();

    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;

}

}




근데 왜케 잡다한버그가 많지