#define _CRT_SECURE_NO_WARNINGS
//猜数字游戏
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
//void menu()
//{
// printf("***************************\n");
// printf("****** 1.play *********\n");
// printf("****** 0.exit *********\n");
// printf("***************************\n");
//
//}
//
//void play()
//{
// int c = 100 + rand() % 101;
// int r = 0;
// while (1)
// {
// printf("请输入你要猜的数\n");
// scanf("%d", &r);
// if (r > c)
// {
// printf("猜大了\n");
// }
// else if (r < c)
// {
// printf("猜小了\n");
// }
// else
// {
// printf("猜对了,数字为%d\n", r);
// break;
// }
// }
//
//}
//
//int main()
//{
// int input;
// srand((unsigned int)time(NULL));
// do
// {
// menu();
// scanf("%d", &input);
// if (input == 1)
// {
// printf("游戏开始\n");
// play();
// }
// else if (input == 0)
// {
// printf("退出游戏\n");
//
// }
// else
// {
// printf("输入错误\n");
// }
//
// } while (input);
// return 0;
//}
//加大挑战,减少为5次机会
//void menu()
//{
// printf("***************************\n");
// printf("****** 1.play *********\n");
// printf("****** 0.exit *********\n");
// printf("***************************\n");
//
//}
//
//void play()
//{
// int count = 7;
// int r = 100 + rand()%101;
// while (count)
// {
// int c = 0;
// printf("请输入你要输入的数\n");
// scanf("%d",&c);
// if (c > r)
// {
// printf("猜大了\n");
// count--;
// }
// else if (c < r)
// {
// printf("猜小了\n");
// count--;
// }
// else
// {
// printf("恭喜你,猜对了,数字是%d",c);
// }
// }
// if (count == 0)
// {
// printf("游戏失败\n");
// }
//}
//
//int main()
//{
// int input = 0;//不可放入do while 循环内,因为出来后while循环的作用域释放了,然后while(input)的时候就找不到;1
// srand((unsigned int)time(NULL));
// do//可以多次玩
// {
// menu();
// printf("请输入\n");
// scanf("%d",&input);
// if (input == 1)
// {
// printf("游戏开始\n");
// play();
// }
// else if (input == 0)
// {
// printf("退出游戏\n");
// break;
// }
// else
// {
// printf("输入错误,请重新输入\n");
// }
// } while (input);
// return 0;
//}
//可以发现在while中声明的位置不受影响
//int main()
//{
// int c = 0;
// scanf("%d",&c);
// while (c)
// {
// if (c == 3)
// {
// printf("hehe\n");
// break;
// }
// }
// return 0;
//}
猜数字游戏
最新推荐文章于 2025-07-18 21:49:12 发布