※以下のソースコードはコピー防止の対応をしています.
01: #include <stdio.h>
02: #include <time.h>
03: #include <stdlib.h>
04:
05: int main(void)
06: {
07: int com;
08: int player = -1;
09: int result; // 0:あいこ, 1:勝ち, 2:負け
10: srand((unsigned)time(NULL));
11:
12: for(result = 0;result == 0;)
13: {
14: com = rand() % 3;
15: for(player = -1;player < 0 || 2 < player;)
16: {
17: printf("じゃんけんぽん(グー:0, チョキ:1, パー:2):");
18: scanf("%d", &player);
19: }
20: printf("COM: ");
21: if(com == 0) printf("グー\n");
22: else if(com == 1) printf("チョキ\n");
23: else printf("パー\n");
24: result = com - player;
25: if(result < 0)result += 3;
26: if(result == 1)printf("勝利!\n");
27: else if(result == 2)printf("敗北...\n");
28: else printf("あいこ\n");
29: }
30:
31: return 0;
32: }