一个简单的猜数字游戏
2016-03-27 20:15
344 查看
猜数字游戏
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
void play_game()
{
srand((unsigned)time(NULL));
int ret = rand() % 101;
int input = 0;
while (1)
{
printf("请猜数字:");
scanf_s("%d", &input);
if (input < ret)
{
printf("猜小了!\n");
}
else if (input > ret)
{
printf("猜大了!\n");
}
else
{
printf("恭喜你,猜对了!\n");
break;
}
}
printf("%d\n", ret);
}
void menu()
{
printf("1.开始游戏 0.退出游戏\n");
}
int main()
{
int choice = 1;
while (choice)
{
menu();
printf("请选择:");
scanf_s("%d", &choice);
switch (choice)
{
case 1:
play_game();
break;
case 0:
break;
}
}
system("pause");
return 0;
}
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
void play_game()
{
srand((unsigned)time(NULL));
int ret = rand() % 101;
int input = 0;
while (1)
{
printf("请猜数字:");
scanf_s("%d", &input);
if (input < ret)
{
printf("猜小了!\n");
}
else if (input > ret)
{
printf("猜大了!\n");
}
else
{
printf("恭喜你,猜对了!\n");
break;
}
}
printf("%d\n", ret);
}
void menu()
{
printf("1.开始游戏 0.退出游戏\n");
}
int main()
{
int choice = 1;
while (choice)
{
menu();
printf("请选择:");
scanf_s("%d", &choice);
switch (choice)
{
case 1:
play_game();
break;
case 0:
break;
}
}
system("pause");
return 0;
}
相关文章推荐
- 月光诗人语录
- Ajax
- JAVA常用集合框架用法详解基础篇二之Colletion子接口List
- 2015级C++第5周项目 类和对象
- 选择排序
- 模拟 csu1711 Kinfolk
- csuoj-1716-Morse
- javascript匿名函数的运用
- 算法训练 矩阵乘方
- Intent之Component
- Android SD卡简单的文件读写操作
- 【机房合作】——备忘录模式
- 第一周------继续
- Android自定义控件系列案例【四】
- linux-matlab2015b安装步骤
- 蓝桥杯:查找整数
- PHP统计目录中文件个数和文件大小
- hdu-A+B问题,大数加法
- 插入排序
- delegate 作为属性,为什么要用weak修饰?