#include<stdio.h>
#include<time.h>
#include<stdlib.h>
void Menu()
{
system("title 猜数字游戏");
system("mode con cols=30 lines=14");
system("color 30");
printf("******************************\n");
printf("********猜数字游戏************\n");
printf("******************************\n");
printf("****[1]开始游戏[0]退出游戏****\n");
printf("******************************\n");
printf("请选择:>");
}
void StartGame()
{
srand(time(0));
int ans = rand() % 100 + 1;
int key;
while (1)
{
system("cls");
printf("请输入你猜的数字:>");
scanf_s("%d", &key);
if (key == ans)
{
printf("恭喜你,猜对了\n");
break;
}
else if(key < ans)
printf("你猜的数字小了...\n");
else
printf("你猜的数字大了...\n");
system("pause");
}
}
int main()
{
int select = 1;
while (select)
{
Menu();
scanf_s("%d", &select);
if (select == 0)
break;
if (select != 1)
{
printf("输入错误,请重新输入....\n");
continue;
}
StartGame();
}
printf("Game Over\n");
return 0;
}