#include <stdio.h>
//0(가위), 1(바위), 2(보)
int get_user_choice(){
int i;
do{
printf("\nselect 0, 1, 2: ");
scanf("%d", &i);
}while(i<0||i>2);
return i;
}
//반환값: 0(무승부), 1(p1 승리), 2(p2 승리)
int get_winner(int p1, int p2){
if(p1==0){
if(p2==1){
return 2;
}
else if(p2==0){
return 0;
}
else if(p2==2){
return 1;
}
}
if(p1==1){
if(p2==1){
return 0;
}
else if(p2==0){
return 1;
}
else if(p2==2){
return 2;
}
}
if(p1==2){
if(p2==1){
return 1;
}
else if(p2==0){
return 2;
}
else if(p2==2){
return 0;
}
}
}
void print_hand(int hand){
if (hand==0){
printf("가위");
}
else if(hand==1){
printf("바위");
}
else if (hand==2){
printf("보");
}
else{
printf("err");
}
}
int main() {
int player1, player2;
int result;
//반환값: 0(무승부), 1(p1 승리), 2(p2 승리)
player1=get_user_choice();
print_hand(player1);
player2=get_user_choice();
print_hand(player2);
result=get_winner(player1, player2);
printf("\n");
if(result==0){
printf("무승부");
}
else if(result==1){
printf("player1 승리 ");
}
else{
printf("player2 승리");
}
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: