#include<stdio.h>
#include<windows.h>
#include<stdlib.h>//srand 在系统中随机种一个种子
#include<time.h>
#pragma warning(disable:4996)
void menu()
{
printf("1.Guess 2.Quit\n");//让玩家进行选择要不要开始游戏
printf("please selsct");
}
void Game()
{
srand((unsigned int)time(NULL));
int data = rand() % 100 + 1;//生成随机数
for (;;){
printf(".....游戏开始.....\n");
printf("Guess:");
int x = 0;
scanf("%d", &x);
if (x > data)
{
printf("你猜大了!\n");
}
else if (x < data)
{
printf("你猜小了!\n");
}
else
{
printf("你猜对了,数字是%d\n", data);
break;//猜对即跳出循环
}
}
printf(".....游戏结束.....");
}
int main()
{
int quit = 0;
while (!quit){
menu();
int select = 0;
scanf("%d", &select);
switch (select)
{
case 1:
Game();
printf("要不要再来一把\n");
break;
case 2:
quit = 1;
printf("Game end\n");
break;
default:
printf("你的输入有误,请重新输入\n");
break;
}
}
system("pause");
return 0;
}
c语言简单猜数字小游戏
最新推荐文章于 2022-04-18 23:09:39 发布