#include<stdio.h> void menu() { printf("*************歡迎進入石頭剪刀布游戲************\n"); printf("*******************1.start>********************\n"); printf("*******************0.exit >********************\n"); printf("***********************************************\n"); } int main() { int input = 1; char ch[10]; int n = 0; int b = 0; int i = 0; int j = 0; int k = 0; int a = 0; while (input) { menu(); printf("請選擇>"); scanf("%d", &input); switch (input) { case 1: {for (i = 0; i < 3; i++) { srand((unsigned int)time(NULL)); n = rand() % 3; printf("請出石頭-剪刀-布\n"); scanf("%s", ch); if (strcmp(ch, "石頭") == 0) b = 0; else if (strcmp(ch, "剪刀") == 0) b = 1; else if (strcmp(ch, "布") == 0) b = 2; if (b == n) { printf("平局\n"); k++; } else if ((b == 0) && (n == 1)) { printf("恭喜你贏了\n"); j++; } else if ((b == 0) && (n == 2)) { printf("很遺憾你輸了\n"); a++; } else if ((b == 1) && (n == 0)) { printf("很遺憾你輸了\n"); a++; } else if ((b == 1) && (n == 2)) { printf("恭喜你贏了\n"); j++; } else if((b == 2) && (n == 0)) { printf("恭喜你贏了\n"); j++; } else { printf("很遺憾你輸了\n"); a++; } if (j == 2) { break; } if (a == 2) { break; } } } if (j == 2) { printf("恭喜你這一局贏了\n"); break; } else if (a == 2) { printf("很遺憾這一局你輸了\n"); break; } else if (k == 3) { printf("這局是平局\n"); break; } else if ((k==2)&&(a==1)) { printf("很遺憾這一局你輸了\n"); break; } else if ((k == 2) && (j == 1)) { printf("恭喜你這一局贏了\n"); break; } default: { printf("退出游戲\n"); system("pause"); exit(0); break; } } } system("pause"); return 0; }