#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int Check(int *Com, int *You, int *Result) //숫자 비교
{
int i, j;
int strike = 0, ball = 0;
for (i = 0; i < 3; i++) //strike, ball 판별
{
for (j = 0; j < 3; j++)
{
if (Com[i] == You[j])
{
if (i == j)
strike++;
else
ball++;
}
}
}
Result[0] = strike;
Result[1] = ball;
if (strike == 3) //strike 3일 경우
Result[2] = 1;
return 0;
}
int main(void)
{
int Com[3] = { 0 };
int You[3] = { 0 };
int Result[3] = { 0 }; //strike, ball, limit
int count = 1;
int i;
printf("Start Game! \n");
srand((int)time(NULL)); //랜덤
for (i = 0; i<3; i++) //랜덤 숫자 생성
{
Com[i] = rand() % 10;
if (i == 1 && (Com[0] == Com[1])) i--;
else if (i == 2 && ((Com[0] == Com[2]) || (Com[1] == Com[2]))) i--;
}
while (Result[2]==0) //숫자 판별
{
printf("Input Three Number: ");
for (i = 0; i < 3; i++) { scanf("%d", &You[i]); }
Check(Com, You, Result);
printf("%d. Result: %dstrike, %dball!! \n", count, Result[0], Result[1]);
count++;
Result[0] = 0;
Result[1] = 0;
}
printf("Game Over! \n");
return 0;
}
'SW Study > 윤성우 C 프로그래밍' 카테고리의 다른 글
도전! 프로그래밍4 도전2 (0) | 2019.10.10 |
---|---|
도전! 프로그래밍4 도전1 (0) | 2019.10.10 |
도전! 프로그래밍3. 도전 5 (0) | 2019.10.02 |
도전! 프로그래밍3. 도전 4 (0) | 2019.10.01 |
도전! 프로그래밍3. 도전 3 (0) | 2019.10.01 |