작은숲:위키노트/C 언어 예제/야구 게임 만들기: 두 판 사이의 차이
잔글 (Utolee90님이 위키노트:C 언어 예제/야구 게임 만들기 문서를 C 언어 예제/야구 게임 만들기 문서로 이동했습니다: Move_Pages_by_removing_the_text_위키노트_via_pywikibot) |
편집 요약 없음 |
||
| (다른 사용자 한 명의 중간 판 4개는 보이지 않습니다) | |||
| 1번째 줄: | 1번째 줄: | ||
< | <syntaxhighlight lang="c"> | ||
/** | /** | ||
* Copyright (c) 2001,2002 Yoon, Hyunho <hhyoon@kldp.org> | * Copyright (c) 2001,2002 Yoon, Hyunho <hhyoon@kldp.org> | ||
| 27번째 줄: | 27번째 줄: | ||
#define FOREVER 1 | #define FOREVER 1 | ||
#define NUM 4 | #define NUM 4 | ||
int | int Random(int from, int to); | ||
void main() | void main() | ||
{ int i = 0, j; | { int i = 0, j; | ||
| 70번째 줄: | 70번째 줄: | ||
break; | break; | ||
} | } | ||
}int | }int Random(int from, int to) | ||
{ if (from > to) | { if (from > to) | ||
return 0; | return 0; | ||
return (rand() % (to - from + 1) + from); | return (rand() % (to - from + 1) + from); | ||
}</ | }</syntaxhighlight> | ||
{{C 언어 예제}} | {{C 언어 예제}} | ||
[[분류:공유]] | [[분류:위키노트/공유]] | ||
[[분류:C 언어]]{{퍼온문서|위키노트|{{#invoke:string|replace|{{PAGENAME}}|위키노트:|}}}}[[분류:위키노트에서 가져온 문서]] | [[분류:C 언어]]{{퍼온문서|위키노트|{{#invoke:string|replace|{{PAGENAME}}|위키노트:|}}}}[[분류:위키노트에서 가져온 문서]] | ||
2023년 5월 23일 (화) 13:34 기준 최신판
/**
* Copyright (c) 2001,2002 Yoon, Hyunho <hhyoon@kldp.org>
* http://mooo.org
* ----------------------------------------------------------------------
*
* LICENSE
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <string.h>
#define FOREVER 1
#define NUM 4
int Random(int from, int to);
void main()
{ int i = 0, j;
int strike, ball;
int num[NUM], user[NUM];
char temp[81];
srand((unsigned)time(NULL));
while (i < NUM) {
num[i] = random(1, 9);
for (j = 0; j < i; j++)
if (num[j] == num[i])
break;
if (i == j)
i++;
}
while (FOREVER) {
do {
printf("Enter 4 digits [1-9]: ");
gets(temp);
if (temp[0] == 'q' || temp[0] == '0')
exit(0);
for (i = 0; i < NUM; i++)
if (temp[i] >= '1' && temp[i] <= '9')
user[i] = temp[i] - '0';
else
break;
if (i != NUM)
continue;
} while (strlen(temp) != 4);
for (i = 0, strike = 0, ball = 0; i < NUM; i++) {
for (j = 0; j < NUM; j++) {
if (num[i] == user[j]) {
if (i == j)
strike++;
else
ball++;
}
}
}
printf("%d strike %d ball\n", strike, ball);
if (strike >= 4)
break;
}
}int Random(int from, int to)
{ if (from > to)
return 0;
return (rand() % (to - from + 1) + from);
}