[置顶] 【C语言】 猜数字游戏
2016-05-26 12:23
405 查看
#include <stdio.h> #include <stdlib.h> #include <time.h> void game() { int input = 0; printf("欢迎使用猜数字游戏\n"); srand((unsigned int)time(NULL)); int ret = rand() % 100; do { printf("请输入你猜的数字:>"); scanf_s("%d", &input); if (input > ret) { printf("您猜得太大了\n"); } else if (input < ret) { printf("您猜得太小了\n"); } else { printf("恭喜你猜对了\n"); break; } } while (1); } void menu() { printf("************************\n"); printf("**** 1.开始游戏 ********\n"); printf("**** 0.退出游戏 ********\n"); printf("************************\n"); } int main() { int choice = 1; while (choice) { menu(); printf("请选择:>"); scanf_s("%d", &choice); switch (choice) { case 1: game(); break; default: break; } } system("pause"); return 0; }
本文出自 “Vs吕小布” 博客,请务必保留此出处http://survive.blog.51cto.com/10728490/1702474
相关文章推荐
- [置顶] 【C语言】 n个不同的数可组成多少个不同的三位数
- [置顶] 【C语言】求最大最小值
- [置顶] 【C语言】一分钟后关机
- [置顶] 【C语言】判断花括号{}是否匹配
- [置顶] 【C语言】求 a+aa+aaa+aaaa+aaaaa
- [置顶] 【C语言】模拟三次密码输入
- [置顶] 【C语言】输出字符串
- [置顶] 【C语言】输出一个整数的每一位
- [置顶] 【C语言】输出菱形星号图案
- [置顶] 【C语言】接收字符,大小写字符相互转换后输出,数字不输出
- [置顶] 【C语言】求两个数的最大公约数
- [置顶] 【C语言】三个数从大到小输出
- [置顶] 【C语言】获取一个数二进制序列中所有的偶数位和奇数位,分别输出二进制序列
- [置顶] 【C语言】 gets()和scanf()函数的区别
- [置顶] 【C语言】交换两个数组内容(数组等大)
- [置顶] 【C语言】求1+2!+3!+...+20!的和
- [置顶] 【C语言】输入十个数求最大数
- [置顶] 【C语言】摄氏温度转化为相应的华氏温度
- 2015级C++第14周程序阅读 STL中的简单容器和迭代器
- C/C++中的&&和||运算符