#include<stdio.h> void menu() { printf("***************************\n"); printf("***********1>start*********\n"); printf("***********2>exit *********\n"); printf("***************************\n"); } int main() { int input=1; int n = 0; int ch = 0; printf("****歡迎使用猜數字游戲*****\n"); while (input) { menu(); printf("請選擇>\n"); scanf("%d", &input); switch (input) { case 1: srand((unsigned int)time(NULL)); n = rand() % 101; while (1) { printf("請輸入一個0-100之間的數\n"); scanf("%d", &ch); if (ch<n) { printf("你猜小了\n"); } else if (ch>n) { printf("你猜大了\n"); } if (ch == n) { printf("恭喜你猜對了\n"); break; } } break; default: printf("退出游戲\n"); break; } } system("pause"); return 0; }