본문 바로가기
프로그램/C언어 1000제

C언어 107제] C언어 콘서트 CHAPTER 11 Programming 7 열거형 사용하기 p456

by 건티 2022. 1. 19.
728x90

출처 : 반크_세계유산 고인돌

 

참고풀이]

//Dev-C++ 5.11로 작업함.
#include <stdio.h>
#include <stdlib.h> //srand(), rand()
#include <time.h> //time()

int main()
{
   enum Game { kawee, bawee, bo};
   int N; //player 변수
   int C; //컴퓨터 변수
   int chk; //결과승부 변수

 

   //무작위 값을 산출하기 위한 초가값 설정
   srand(time(NULL));

   printf("가위(0), 바위(1), 보(2)를 입력하세요 : ");
   scanf("%d",&N);

   C=rand()%3;

   if(N==C) chk=0;
   else if(N==kawee)
      if(C==bo) chk=1;
      else if(C==bawee)chk=-1;
   else if(N==bawee)
      if(C==kawee) chk=1;
      else if(C==bo) chk=-1;
   else if(N==bo)
      if(C==bawee) chk=1;
      else if(C==kawee) chk=-1;

   if(chk==1) 
      printf("Player가 이겼습니다.\n");
   else if(chk==-1)
      printf("Computer가 이겼습니다.\n");
   else
      printf("비겼습니다.\n");

   return 0;
}

 

참고풀이 결과]

 

 

 

 

대한민국의 아름다운 영토, 독도

 

반응형

댓글