include <stdio.h> #include <stdlib.h> #include <time.h> void print_menu() { printf("**********************\n"); printf("******* 1.start ******\n"); printf("******* 0. exit ******\n"); printf("**********************\n"); } int main() { int input = 1; printf("歡迎使用猜數字游戲\n"); while (input) { print_menu(); printf("請選擇>"); scanf("%d", &input); switch (input) { case 1: { int n = 0; int ch = 0; 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"); } else { printf("恭喜你,猜對了\n"); break; } } break; } default: printf("游戲退出\n"); break; } } system("pause"); return 0; }