#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void game(int user_choice, int computer_choice){
switch (computer_choice)
{
case 1:
if (user_choice == 1)
{
printf("컴퓨터 : 묵\n인간 : 묵\n");
printf("무승부!\n");
}
else if (user_choice == 2)
{
printf("컴퓨터 : 묵\n인간 : 찌\n");
printf("컴퓨터 승리!\n");
}
else if (user_choice == 3)
{
printf("컴퓨터 : 묵\n인간 : 빠\n");
printf("인간 승리!\n");
}
break;
case 2:
if (user_choice == 1)
{
printf("컴퓨터 : 찌\n인간 : 묵\n");
printf("인간 승리!\n");
}
else if (user_choice == 2)
{
printf("컴퓨터 : 찌\n인간 : 찌\n");
printf("무승부!\n");
}
else if (user_choice == 3)
{
printf("컴퓨터 : 찌\n인간 : 빠\n");
printf("컴퓨터 승리!\n");
}
break;
case 3:
if (user_choice == 1)
{
printf("컴퓨터 : 빠\n인간 : 묵\n");
printf("컴퓨터 승리!\n");
}
else if (user_choice == 2)
{
printf("컴퓨터 : 빠\n인간 : 찌\n");
printf("인간 승리!\n");
}
else if (user_choice == 3)
{
printf("컴퓨터 : 빠\n인간 : 빠\n");
printf("무승부!\n");
}
break;
default:
printf("올바른 입력값을 입력해주세요!");
break;
}
}
int main(){
int user_choice;
int computer_choice;
printf("Hello Rock, Sissor, Paper World!!\n");
printf("Choice One!\n");
printf("1. Rock\n");
printf("2. Sissor\n");
printf("3. Paper\n");
printf("Enter : ");
scanf("%d", &user_choice);
srand(time(NULL)); // 시간을 시드 값으로 사용하여 랜덤 숫자 초기화
computer_choice = rand()%3 + 1; // 1부터 3 사이의 랜덤한 수 출력
printf("컴퓨터 선택 테스트 출력 : %d\n", computer_choice);
game(user_choice, computer_choice);
return 0;
}
ㅆㅎㅌㅊ
근데 묵찌빠는 뭐 별거없어서 거기서 거기임
숙제: else if문 사용하지 않도록 리펙토링 해보세요
매직넘버 사용하지마라
몇줄이면 나올텐데 복잡하게 만들어