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