#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void game()
{
int input = 0;
printf("歡迎使用猜數字游戲\n");
srand((unsigned int)time(NULL));
int ret = rand() % 100;
do
{
printf("請輸入你猜的數字:>");
scanf_s("%d", &input);
if (input > ret)
{
printf("您猜得太大了\n");
}
else if (input < ret)
{
printf("您猜得太小了\n");
}
else
{
printf("恭喜你猜對了\n");
break;
}
} while (1);
}
void menu()
{
printf("************************\n");
printf("**** 1.開始游戲 ********\n");
printf("**** 0.退出游戲 ********\n");
printf("************************\n");
}
int main()
{
int choice = 1;
while (choice)
{
menu();
printf("請選擇:>");
scanf_s("%d", &choice);
switch (choice)
{
case 1:
game();
break;
default:
break;
}
}
system("pause");
return 0;
}