#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main() {
    srand(time(NULL)); //난수 초기화
    int real_t = rand() % 4; //난수 생성, 진짜 발모제 선택하기 (0~3)
    printf("===자라나라 머리카락 게임===\n");
    int cnt_b = 0; //이번 회차의 조합한 약병
    int pre_b = 0; //저번 회차의 조합한 약병
    for(int i=1;i<=3;i++){
        int bottle[4] = {0, 0, 0, 0}; //4개 종류의 약병
        do{
            cnt_b = rand() % 2 + 2; //2~3개 병을 섞게 됨
        }while(cnt_b == pre_b); //현재와 이전이 다를 때까지
        pre_b = cnt_b;
        printf(" > %d번째 테스트: \n", i);
        //조합할 약병 번호 선택하기
        int Isinclude = 0; //진짜 발모제인지 확인용
        for(int j=0;j<cnt_b;j++){
            int randBottle = rand() % 4; //약병 번호 뽑기 (0~3)
            if(bottle[randBottle] == 0){ //아직 선택되지 않았다면
                bottle[randBottle] = 1;
                if(randBottle == real_t){
                    Isinclude = 1;
                }
            }else {
                j--;
            }
        }
        for(int k=0;k<4;k++){
            if(bottle[k] == 1){
                printf("%d ", k+1);
            }
        }
        printf("번 물약을 머리에 바릅니다\n\n");
        if(Isinclude == 1) { //진짜 발모제가 포함되어 있으면
            printf(">> 성공! 머리카락이 자라났어요!!\n");
        }else{
            printf(">> 실패! 머리카락이 자라나지 않았어요. ㅜㅜ\n");
        }
        printf("\n   계속하려면 Enter를 누르세요. \n");
        getchar();
    }
    //사용자 입력받기
    printf("\n\n 발모제는 몇 번일까요?");
    int answer;
    scanf("%d", &answer);
    if (answer == real_t + 1){
        printf("\n >>정답입니다!\n");
    }else{
        printf("\n >>틀렸습니다 진짜 정답은 %d번 입니다.\n", real_t + 1);
    }
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: