#include<stdio.h> # include<stdlib.h> # include<time.h> void menu() { printf("*********************\n"); printf("歡迎進入該游戲系統!\n"); printf("選擇:\n"); printf("1:start\n"); printf("2:exit\n"); printf("*********************\n"); } int game(int n) { int i; while(1) { printf("輸入你猜的數字:"); scanf("%d",&i); if(i<n) printf("你猜小了;"); if(i>n) printf("你猜大了;"); if(i==n) { printf("恭喜你,你猜對了!"); return 0; } // } } int main() { srand((unsigned int)time(NULL)); int ret=rand(); int m=ret%100; int a; menu(); printf("輸入:"); scanf("%d",&a); switch(a) { case 1: game(m); break; case 2: printf("exit\n"); break; } return 0; }