|
int c[3], m[3];
위와 같이 배열이 정의되어 있다면
그 인덱스는 0~2 입니다.
이태관 님이 쓰신 글 :
: 안녕하세요?
:
: 야구 게임을 만들었는데..
: 영.. 시원찮습니다.
: 뭐가 잘못됐는지 알려주세요.
: ㅠ.ㅠ
:
: #include <stdio.h>
: #include <stdlib.h>
: void main()
: {
: int c[3], m[3],i,j,k,ball,strike;
: randomize();
:
: c[0]=random(9)+1;
: do {
: c[1]=random(9)+1;
: } while(c[0]==c[1]);
: do {
: c[2]=random(9)+1;
: } while(c[0]==c[2] || c[1]==c[3]);
: strike=ball=0;
:
: do {
: k++;
: printf("\nEnter Three digit~! : ");
: do {
: scanf("%d, %d, %d",&m[0],&m[1],&m[2]);
: if (m[0]==m[1] || m[1]==m[2] || m[0]==m[3])
: printf("plase enter another number~!!\n");
: } while(m[0]==m[1] || m[1]==m[2] || m[0]==m[3]);
: for(i=0;i<3;i++)
: {
: for(j=0;j<3;j++)
: {
: if (c[i]==m[j] && i==j) strike++;
: else if (c[i]==m[j]) ball++;
: }
: }
: printf("Strike : %d, Ball : %d\n",strike,ball);
: } while(strike<3 && k<8);
: if(strike=3) printf("Congratulation!\n");
: else printf("Sorry Try Again~!\n");
: }
|