#include <stdio.h>

#include <stdlib.h>

#include <time.h>


int BaseballCheck(int *randomnum, int *usernum)

{

//strike 개수 세기 시작

int strikenum = 0;

for (int i = 0; i < 3; i++)

{

if (randomnum[i] == usernum[i])

strikenum++;

}

printf("\nStrike : %d \n", strikenum);

//strike 개수 세기 끝


//ballnum 개수 세기 시작

int ballnum = 0;

for (int i = 0; i < 3; i++)

{

for (int j = 0; j < 3; j++)

{

if (randomnum[i] == usernum[j])

ballnum++;

}

}

ballnum = ballnum - strikenum;

printf("ball : %d \n\n", ballnum);

if (strikenum == 3)

return 1;

return 0;

}



int main(void)

{

int usernum[3]; // 유저가 입력한 수 asd순으로 백의자리 십의자리 일의자리

int randomnum[3]; // 컴퓨터가 만든 수 q = 백의자리, w = 십의자리, e = 일의자리 

int trynum = 1; // 시도횟수

int out=0;

char moregame;

onemore:

srand((int)time(NULL));

retry:

randomnum[0] = rand();

randomnum[1] = rand() % 10;

randomnum[2] = rand() % 10;

if ((randomnum[0] == 0) || (randomnum[0] == randomnum[1]) || (randomnum[0] == randomnum[2]) || (randomnum[1] == randomnum[2]))

goto retry;

printf("%d %d %d \n------\n\n", randomnum[0], randomnum[1], randomnum[2]);

// 서로다른 세자리 수 만듦 끝

printf("- Game Start -\n\n");

while (1)

{

printf("%d번째 시도 \n", trynum);

printf("3개의 숫자 선택 (n n n 형식으로 입력)\n");

scanf_s("%d %d %d", &usernum[0], &usernum[1], &usernum[2]);

out = BaseballCheck(randomnum, usernum);

if (out == 1)

break;

trynum++;

}

printf("한번 더? (y/n) \n");

scanf_s("%c", &moregame);   //  scanf_s 부터  그 밑으로 실행이 안되는듯 "한번 더? (y/n)하고 바로 꺼져버림 왜이런가요 해결방법도부탁

if (moregame == 'y')

{

system("cls");

goto onemore;

}

return 0;

}

/*


제목이 곧 내용이네요


알려주세요 부탁드려요 ㅜㅜ 이런거 물어볼 곳이 없네요


알고나서 삭제하겠습니다


*

/*


제목이 곧 내용이네요


알려주세요 부탁드려요 ㅜㅜ 이런거 물어볼 곳이 없네요


알고나서 삭제하겠습니다


*/