• 카테고리

    질문 & 답변
  • 세부 분야

    프로그래밍 언어

  • 해결 여부

    미해결

Visual Studio가 안꺼집니다..

20.03.05 20:18 작성 조회수 1.01k

0

f5를 눌렀는데 실행이 되지않습니다...ㅠㅠ

Visual Studio는 종료자체가 되지않습니다...

종료버튼을 누르면

'솔루션을 닫으려면 빌드를 중지해야합니다.' 창만 뜨고

종료가 되지않습니다...

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

// 10마리의 서로 다른 동물 (가 카드 2장씩)
// 사용자로부터 2개의 입력값을 받아서 -> 같은 동물 찾으면 카드 뒤집기
// 모든 동물쌍을 찾으면 게임 종료
// 총 실패 횟수 알려기

int arrayAnimal[4][5]; // 카드 지도(20장)
int checkAnimal[4][5]; // 뒤집힌 여부 확인
char * strAnimal[10]; // 동물 이름

void initAnimalArray();
void initAnimalName();
void shuffleAnimal();
int getEmptyPosition();
int conv_pos_x(int x);
int conv_pos_y(int y);
void printAnimals();
void printQuestiom();

int main(void)
{
	srand(time(NULL));

	initAnimalArray();
	initAnimalName();

	shuffleAnimal();

	int failCount = 0; // 실패 횟수

	while (1)
	{
		int select1 = 0; // 사용자가 선택한 첫번째 수
		int select2 = 0; // 사용자가 선택한 두번째 수

		printAnimals(); // 동물 위치 출력
		printQuestiom(); // 문제 출력 (카드지도)
		printf("뒤집을 카드를 2개 고르세요. : ");
		scanf_s("%d, %d", &select1, &select2);

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

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

		// 정수 좌표를 (x,y) 로 변환
		int firstSelect_x = conv_pos_x(select1);
		int firstSelect_y = conv_pos_y(select2);

		int secondSelect_x = conv_pos_x(select1);
		int secondSelect_y = conv_pos_y(select2);

		// 같은 동물인 경우
		if ((checkAnimal[firstSelect_x][firstSelect_y] == 0 
			&& checkAnimal[secondSelect_x][secondSelect_y] == 0) //카드가 뒤집히지 않았는지

			&&

		(arrayAnimal[secondSelect_x][secondSelect_y]
			== arrayAnimal[secondSelect_x][secondSelect_y]) // 두 동물이 같은지
			)
		{
			printf("\nn\n빙고! : %s 발견\n\n", strAnimal[arrayAnimal[secondSelect_x][secondSelect_y]]);
			checkAnimal[firstSelect_x][firstSelect_y] = 1;
			checkAnimal[secondSelect_x][secondSelect_y] = 2;
		}
		// 다른 동물인 경우
		else
		{
			printf("\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++;
		}

		if (foudAllAnimal() == 1)
		{
			printf("\n\n축하합니다 ! 모든 동물들을 다 찾았네요 \n");
			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()
{
	// ㅁㅁㅁㅁㅁ  0  1  2  3  4 -> 0 0 0 0 0
	// ㅁㅁㅁㅁㅁ  5  6  7  8  9 -> 1 1 1 1 1 
	// ㅁㅁㅁㅁㅁ 10 11 12 13 14 -> 2 2 2 2 2
	// ㅁㅁㅁㅁㅁ 15 16 17 18 19 -> 3 3 3 3 3 
	while (1)
	{
		int randPos = rand() % 20; // 0~19 사이의 숫자 반환
		// 19 -> (3,4)
		int x = conv_pos_x(randPos);
		int y = conv_pos_y(randPos);

		if (arrayAnimal[x][y] == -1)
		{
			return randPos;
		}

	}
	return 0;
}

int conv_pos_x(int x)
{
	 //19 -> (3,4)
	return x / 5;
}

int conv_pos_y(int y)
{
	return y % 5; // y를 5로나눈 나머지 값
}

void printAnimals() // 동물 위치 출력
{
	// ㅁㅁㅁㅁㅁ  1  1  2  2  3 
	// ㅁㅁㅁㅁㅁ  4  4  5  5  3 
	// ㅁㅁㅁㅁㅁ
	// ㅁㅁㅁㅁㅁ
	printf("\n========== 이건 비밀인데.. 몰래 보여줍니다 ==========\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\n");
}
void printQuestiom() // 문제 출력 (카드지도)
{
	printf("\n\n(문제)\n");
	int seq = 0;
					//seq				 //checkAnimal
	// ㅁㅁㅁㅁㅁ  0  1  2  3  4           0 0 0 0 0
	// ㅁㅁㅁㅁㅁ  5  6  7  8  9           1 0 0 0 1 
	// ㅁㅁㅁㅁㅁ 10 11 12 13 14           0 0 1 0 0
	// ㅁㅁㅁㅁㅁ 15 16 17 18 19           1 0 0 1 1

	for (int i = 0; i < 4; i++)
	{
		for (int j = 0; j < 5; j++)
		{
			// 카드를 뒤집어서 정답을 맞췄으면 '동물이름'
			if (checkAnimal[i][j] != 0) // != 는 ≠
			{
				printf("%8s", strAnimal[i][j]);
			}
			// 아직 뒤집지 못했으면 (정답을 못맞췄으면) 뒷면 -> 위치를 나타내는 숫자
			else
			{
				printf("%8d", seq);
			}
		}
	}
}

int foudAllAnimal()
{
	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

안녕하세요 ^^

코드에 오류가 여러 군데 있었네요

모두 수정하였으니 확인해보세요. 수정한 곳은 모두 주석으로 뒤에

// 수정 전 : (수정 전의 코드)

이런 식으로 적혀 있으니 비교해보실 수 있을겁니다 ^^

감사합니다.

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

// 10마리의 서로 다른 동물 (가 카드 2장씩)
// 사용자로부터 2개의 입력값을 받아서 -> 같은 동물 찾으면 카드 뒤집기
// 모든 동물쌍을 찾으면 게임 종료
// 총 실패 횟수 알려기

int arrayAnimal[4][5]; // 카드 지도(20장)
int checkAnimal[4][5]; // 뒤집힌 여부 확인
char* strAnimal[10]; // 동물 이름

void initAnimalArray();
void initAnimalName();
void shuffleAnimal();
int getEmptyPosition();
int conv_pos_x(int x);
int conv_pos_y(int y);
void printAnimals();
void printQuestiom();

int main(void)
{
	srand(time(NULL));

	initAnimalArray();
	initAnimalName();

	shuffleAnimal();

	int failCount = 0; // 실패 횟수

	while (1)
	{
		int select1 = 0; // 사용자가 선택한 첫번째 수
		int select2 = 0; // 사용자가 선택한 두번째 수

		printAnimals(); // 동물 위치 출력
		printQuestiom(); // 문제 출력 (카드지도)
		printf("뒤집을 카드를 2개 고르세요. : ");
		scanf_s("%d %d", &select1, &select2); // 수정 전 : %d, %d

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

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

		// 정수 좌표를 (x,y) 로 변환
		int firstSelect_x = conv_pos_x(select1);
		int firstSelect_y = conv_pos_y(select1); // 수정 전 : select2

		int secondSelect_x = conv_pos_x(select2); // 수정 전 : select1
		int secondSelect_y = conv_pos_y(select2);

		// 같은 동물인 경우
		if ((checkAnimal[firstSelect_x][firstSelect_y] == 0
			&& checkAnimal[secondSelect_x][secondSelect_y] == 0) //카드가 뒤집히지 않았는지

			&&

			(arrayAnimal[firstSelect_x][firstSelect_y] // 수정 전 : (arrayAnimal[secondSelect_x][secondSelect_y]
				== arrayAnimal[secondSelect_x][secondSelect_y]) // 두 동물이 같은지
			)
		{
			printf("\nn\n빙고! : %s 발견\n\n", strAnimal[arrayAnimal[firstSelect_x][firstSelect_y]]); // 수정 전 : strAnimal[arrayAnimal[secondSelect_x][secondSelect_y]]);
			checkAnimal[firstSelect_x][firstSelect_y] = 1;
			checkAnimal[secondSelect_x][secondSelect_y] = 1; // 수정 전 : 2
		}
		// 다른 동물인 경우
		else
		{
			printf("\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++;
		}

		if (foudAllAnimal() == 1)
		{
			printf("\n\n축하합니다 ! 모든 동물들을 다 찾았네요 \n");
			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()
{
	// ㅁㅁㅁㅁㅁ  0  1  2  3  4 -> 0 0 0 0 0
	// ㅁㅁㅁㅁㅁ  5  6  7  8  9 -> 1 1 1 1 1 
	// ㅁㅁㅁㅁㅁ 10 11 12 13 14 -> 2 2 2 2 2
	// ㅁㅁㅁㅁㅁ 15 16 17 18 19 -> 3 3 3 3 3 
	while (1)
	{
		int randPos = rand() % 20; // 0~19 사이의 숫자 반환
		// 19 -> (3,4)
		int x = conv_pos_x(randPos);
		int y = conv_pos_y(randPos);

		if (arrayAnimal[x][y] == -1)
		{
			return randPos;
		}

	}
	return 0;
}

int conv_pos_x(int x)
{
	//19 -> (3,4)
	return x / 5;
}

int conv_pos_y(int y)
{
	return y % 5; // y를 5로나눈 나머지 값
}

void printAnimals() // 동물 위치 출력
{
	// ㅁㅁㅁㅁㅁ  1  1  2  2  3 
	// ㅁㅁㅁㅁㅁ  4  4  5  5  3 
	// ㅁㅁㅁㅁㅁ
	// ㅁㅁㅁㅁㅁ
	printf("\n========== 이건 비밀인데.. 몰래 보여줍니다 ==========\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\n");
}
void printQuestiom() // 문제 출력 (카드지도)
{
	printf("\n\n(문제)\n");
	int seq = 0;
	//seq				 //checkAnimal
// ㅁㅁㅁㅁㅁ  0  1  2  3  4           0 0 0 0 0
// ㅁㅁㅁㅁㅁ  5  6  7  8  9           1 0 0 0 1 
// ㅁㅁㅁㅁㅁ 10 11 12 13 14           0 0 1 0 0
// ㅁㅁㅁㅁㅁ 15 16 17 18 19           1 0 0 1 1

	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]]); // 수정 전 : strAnimal[i][j]);
			}
			// 아직 뒤집지 못했으면 (정답을 못맞췄으면) 뒷면 -> 위치를 나타내는 숫자
			else
			{
				printf("%8d", seq);
			}
			seq++; // 수정 전 : 비어있었음
		}
		printf("\n"); // 수정 전 : 비어있었음
	}
}

int foudAllAnimal()
{
	for (int i = 0; i < 4; i++)
	{
		for (int j = 0; j < 5; j++)
		{
			if (checkAnimal[i][j] == 0)
			{
				return 0;
			}
		}
	}
	return 1; // 모두 다 찾음
}