가위바위보를 이렇게 작성해봤습니다.
메인함수 이외에 사용자 정의 함수를 3개를 사용하라고 하셔서 고치려는데
혹시 도와주실 분 계신가요?
제 코딩실력이 너무 부족해서 도움이 필요합니다.
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
char RPS_GAME[3][10] = { "가위", "바위", "보" };
int main(void)
{
int user;
int com;
srand((unsigned int)time(NULL));
printf("가위바위보 게임입니다.\n");
while (1) {
com = rand() % 3 + 1;
printf("유저가 낼 차례입니다.(1:가위 2:바위 3:보 0:종료) : ");
scanf("%d", &user);
if (user == 0) {
break;
}
else if (0 > user || user > 3) {
printf("잘못 입력하였습니다. 다시 해주세요.\n");
continue;
}
printf("당신은 %s를 냈습니다.\n", RPS_GAME[user - 1]);
printf("컴퓨터는 %s를 냈습니다.\n", RPS_GAME[com - 1]);
if (com == user) {
printf("비겼습니다.\n");
}
if (user == 1) {
if (com == 2) {
printf("컴퓨터 승리\n");
}
else if (com == 3) {
printf("유저 승리\n");
}
}
else if (user == 2) {
if (com == 3) {
printf("컴퓨터 승리\n");
}
else if (com == 1) {
printf("유저 승리\n");
}
}
else if (user == 3) {
if (com == 1) {
printf("컴퓨터 승리\n");
}
else if (com == 2) {
printf("유저 승리\n");
}
}
printf("\n");
}
}
댓글 입력