검색결과 리스트
글
야구
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main()
{
int com[3];
int game[3];
char yes_no;
int strike,ball,count;
srand(time(NULL));
printf("야구게임 시작\n");
while(1)
{
//3개 랜덤입력
com[0]=rand()%10;
com[1]=rand()%10;
com[2]=rand()%10;
//중복 확인
if(com[0]==com[1] || com[0]==com[2] || com[1]==com[2])
continue;
count=1;
while(1)
{
ball=0,strike=0;
//사용자 입력
printf("0~9까지 수 입력 : ");
scanf("%d %d %d",&game[0],&game[1],&game[2]);
if(com[0]==game[0])strike++;
else if(com[0]==game[1] || com[0]==game[2])ball++;
if(com[1]==game[1])strike++;
else if(com[1]==game[0] || com[1]==game[2])ball++;
if(com[2]==game[2])strike++;
else if(com[2]==game[1] || com[2]==game[0])ball++;
printf("%d회 %d번 스트라이크 %d번 볼\n",count++,strike,ball);
if(strike==3)
break;
}
ffulsh(stdin)
printf("게임을 계속 하시겠습니까 y/n ?");
scanf("%c",&yes_no);
if(yes_no=='n' || yes_no=='N')
break;
}
}