#include<stdio.h>


int main()

{

    double operand, total; // 콤마 연산자 뒤에 한 칸 띄움

    int count, retry, for_retry;

    count = retry = total = for_retry = 0;


    printf(" 평균 구하기 ");

    do

    {

        for(; for_retry == 0;) // 세미콜론 뒤에 한 칸 띄움 2항 연산자 좌우로 한 칸씩 띄움

        {

            printf("%d 번째의 값을 입력해 주십시오(negative input to quit) ", count + 1);

            scanf("%lf", &operand);

            if(operand > 0)

            {

                total += operand;

                count++;

                for_retry = 0;

            }

            else if(operand < 0)

            {

                for_retry=1;

            }

        }

        printf("%d개의 숫자의 평균값은 %lf 입니다.\n", count, total / count);

        printf("다시 하시겠습니까? (Y/n)"); // 사소한 약속인데, 대문자로 쓴 Y 는 아무거나 입력하면 yes 로 받아들인다(default)의 의미

        scanf("%c", &for_retry);

        if(for_retry == 1)

        {

            for_retry = --for_retry;

            total = count = 0;

        }

        else if(for_retry == 2)

        {

            for_retry = --for_retry;

        }

        else // 블럭으로 쌌던 else 는 블럭으로 싸줘서 규칙적으로 보이게 해라. 규칙성이 흐트러지면 사소한 오류가 눈에 잘 안들어와.

        {

            printf("잘못된 번호입니다. 그러므로 종료합니다 ");

        }

    }while(for_retry == 0);

    return 0;

}