• 카테고리

    질문 & 답변
  • 세부 분야

    프로그래밍 언어

  • 해결 여부

    미해결

빌드오류가 있다고 나오고, 지정된 파일을 찾을 수 없다고 오류가 나옵니다..

23.02.21 18:28 작성 조회수 238

0

#include<stdio.h>

#include<time.h>

#include<stdlib.h>

/*10마리의 서로다른 동물 (각 카드 2장씩)

사용자로부터 2개의 입력값을 받아서 -> 같은 동물 찾으면 카드 뒤집기

모든 동물 쌍을 찾으면 게임 종료

총 실패 횟수 알려주기*/

int checkAnimal[4][5]; //뒤집혔는지 여부 확인

int arrayAnimal[4][5]; //카드 20장 - 4x5

const char* strAnimal[10]; //10개의 배열 => 캐릭터포인터

void initAnimalArray(); // 카드 배치

void initAnimalName(); // 동물 종류

void shuffleAnimal(); //카드 섞기

int getEmptyPosition(); //빈 공간 찾기

int conv_pos_x(int x);

int conv_pos_y(int y);

void printAnimals(); //동물 위치 출력

void printQuestion(); // 문제 출력 (카드지도)

int foundAllAnimals();

int main(void)

{

srand(time(NULL));

initAnimalArray();

initAnimalName();

shuffleAnimal();

int failCount = 0; //실패 횟수

while (1)

{

int select1 = 0; //사용자가 선택한 처음 수

int select2 = 0; //사용자가 선택한 두번째 수

printAnimals(); //동물 위치 출력

printQuestion(); // 문제 출력 (카드지도)

printf("뒤집을 카드 2개를 고르세요 : ");

scanf_s("%d %d", &select1, &select2);

if (select1 == select2) // 같은 카드 선택 시 무효

continue;

//좌표에 해당하는 카드를 뒤집어보고 같은지 안같은지 확인

int firstSelect_x = conv_pos_x(select1);

int firstSelect_y = conv_pos_y(select1);

int secondSelect_x = conv_pos_x(select2);

int secondSelect_y = conv_pos_y(select2); //정수좌표를 x,y로 변환

if (checkAnimal[firstSelect_x][firstSelect_y] == 0

&& checkAnimal[secondSelect_x][secondSelect_y] == 0//카드가 뒤집히지 않앗는지

&& arrayAnimal[firstSelect_x][firstSelect_y]

== arrayAnimal[secondSelect_x][secondSelect_y])//두 동물이 같은지)

{

printf("\n\n빙고!! : %s 발견!!\n\n",strAnimal[arrayAnimal[firstSelect_x][firstSelect_y]]);

checkAnimal[firstSelect_x][firstSelect_y] = 1;

checkAnimal[secondSelect_x][secondSelect_y] = 1;

}

//다른 동물일 경우

else

{

printf("\n\n땡!!(틀렸습니다.. 혹은 이미 뒤집힌 카드입니다.)\n\n");

printf("%d : %s\n", select1, strAnimal[arrayAnimal[firstSelect_x][firstSelect_y]]);

printf("%d : %s\n", select2, strAnimal[arrayAnimal[secondSelect_x][secondSelect_y]]); //틀린카드 알려주기

printf("\n\n");

failCount++; //실패횟수 +1

}

//모든 동물을 찾았는지 여부. 1:참 , 0:거짓

if (foundAllAnimals() == 1)

{

printf("***축하합니다!총 %d번의 시도끝에 모든 동물을 다 찾았네요***\n",failCount);

break;

}

}

return 0;

}

void initAnimalArray()

{

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

{

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

{

arrayAnimal[i][j] = -1;

}

}

}

void initAnimalName()

{

strAnimal[0] = "강아지";

strAnimal[1] = "고양이";

strAnimal[2] = "토끼";

strAnimal[3] = "다람쥐";

strAnimal[4] = "햄스터";

strAnimal[5] = "청설모";

strAnimal[6] = "오리";

strAnimal[7] = "원숭이";

strAnimal[8] = "미어캣";

strAnimal[9] = "호랑이";

}

void shuffleAnimal()

{

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

{

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

{

int pos = getEmptyPosition();

int x = conv_pos_x(pos);

int y = conv_pos_y(pos);

arrayAnimal[x][y] = i;

}

}

}

int getEmptyPosition()

{

while (1)

{

int randPos = rand() % 20; //0-19사이의 랜덤 숫자 반환

int x = conv_pos_x(randPos);

int y = conv_pos_y(randPos);

if (arrayAnimal[x][y] == -1) //초기에 -1로 설정했기때문에 -1이면 비어있다는 뜻

{

return randPos; //현재 위치 반환

}

}

return 0;

}

int conv_pos_x(int x) //5로 나눴을 때 몫 /

{

return x / 5;

}

int conv_pos_y(int y) //5로 나눴을 때 나머지 %

{

return y % 5;

}

void printAnimals() //동물 위치 출력

{

printf("\n=====이건 비밀인데 몰래 보여드려요=====\n");

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

{

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

{

printf("%8s", strAnimal[arrayAnimal[i][j]]);

}

printf("\n");

}

printf("\n=========================================\n");

}

void printQuestion() // 문제 출력 (카드지도)

{

printf("\n\n(문제)\n");

int seq = 0;

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

{

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

{

//카드를 뒤집어서 정답을 맞혔으면 '동물이름

if (checkAnimal[i][j] != 0)

{

printf("% 8s", strAnimal[arrayAnimal[i][j]]);

}

//아직 뒤집지 못했으면 (정답을 못맞혔으면) -> 뒷면 -> 위치를 나타내는 숫자

else

{

printf("%8d", seq++);

}

}

printf("\n");

}

}

int foundAllAnimals()

{

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

{

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

{

if (checkAnimal[i][j] == 0)

{

return 0;

}

}

}

return 1;//모두 다 찾음

}

답변 1

답변을 작성해보세요.

0

작은새님의 프로필

작은새

2023.05.20

빌드 오류나는 오류 메시지도 같이 올려주시면 좋을 것 같아요.