5x5 그리드판에서 사용자가 (x,y) 위치를 입력하면 그 부분에 'O'
가 생기게하고 빙고가 될시 종료하는 코드를 짜고싶습니다.
int check = 0;
을 선언하고
while
문 코드안에서 checkBingo
함수로 빙고가 되었을 때 check
를 1
로 만들고 check
가 1
이 되면 루프가 멈추게하고 싶은데 안돼요.
//
int check = 0;
int checkBingo(char a[5][5], int check) {
for(int i =0; i<5;i++)
if (a[i][1] == 'O' and a[i][2] == 'O' and a[i][3] == 'O' and a[i][4] == 'O' and a[i][0] == 'O') {
cout << "당신이 이겼습니다." << endl;
check = 1;
}
for (int j = 0; j < 5; j++)
if (a[0][j] == 'O' and a[1][j] == 'O' and a[2][j] == 'O' and a[3][j] == 'O' and a[4][j] == 'O') {
cout << "당신이 이겼습니다." << endl;
check = 1;
}
if (a[0][0] == 'O' and a[1][1] == 'O' and a[2][2] == 'O' and a[3][3] == 'O' and a[4][4] == 'O') {
cout << "당신이 이겼습니다." << endl;
check = 1;
}
if (a[0][4] == 'O' and a[1][3] == 'O' and a[2][2] == 'O' and a[3][1] == 'O' and a[4][0] == 'O') {
cout << "당신이 이겼습니다." << endl;
check = 1;
}
return 0;
}
int main()
{
char a[5][5] = {' '};
cout << "---------------------";
cout << endl;
while (true) {
print(a);
checkBingo(a, check);
if (check == 1)
break;
int x;
int y;
cout << "input : ";
cin >> x >> y;
a[x][y] = 'O';
system("cls");
cout << check;
}
}