#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<time.h>
#include<stdlib.h>
#include<string.h>
void game()
{
int i = 0;
int b = 0;
int guass = 0;
b = rand() % 100 + 1;
printf("只能输入10次噢\n");
for (i = 1; i <= 5; i++)
{
printf("请输入100以内的数字\n");
scanf("%d", &guass);
if (guass < b)
{
printf("输入小了,请重新输入\n");
}
else if (guass > b)
{
printf("输入大了,请重新输入\n");
}
else
{
printf("输入正确\n");
break;
}
}
if (i == 6)
{
int j = 0;
char input[50] = { 0 };
printf("全错了,60秒后给我关机吧\n");
printf("给你10次机会,输入 我是傻逼,猜数字都不会,取消关机\n");
system("shutdown -s -t 60");
for (j = 1; j <= 10; j++)
{
scanf("%s", &input);
if (strcmp(input, "我是傻逼,猜数字都不会") == 0)
{
system("shutdown -a");
printf("取消关机成功");
break;
}
}
}
}
int main()
{
printf("*****************************************\n");
printf("*****************************************\n");
printf("****************1. paly *****************\n");
printf("****************2. exit *****************\n");
printf("*****************************************\n");
printf("*****************************************\n");
int a = 0;
srand((unsigned)time(NULL));
printf("请输入数字\n");
scanf("%d", &a);
switch (a)
{
case 1:
printf("开始游戏\n");
game();
break;
case 2:
printf("退出游戏\n");
break;
default:
printf("输入错误,退出游戏\n");
break;
}
return 0;
}
10次机会猜数字代码,错了就关机
最新推荐文章于 2024-08-29 16:37:54 发布