博客
关于我
C++扬帆远航——16(猜数字)
阅读量:525 次
发布时间:2019-03-08

本文共 786 字,大约阅读时间需要 2 分钟。

猜数字游戏

#include 
#include
#include
using namespace std;int main() { int n, gn; int m = 0; srand((unsigned)time(0)); n = rand() % 1000 + 1; for(;;) { cout << "Please input a number:"; cout << endl; cin >> gn; m++; if(gn > n) { cout << "大了" << endl; } else if(gn < n) { cout << "小了" << endl; } else { cout << "猜对了!" << endl; cout << "一共猜了" << m << "次" << endl; break; } return 0; }}

心得

这个程序是一个简单的猜数字游戏,用户需要通过输入猜测数字来猜出随机生成的1000以内的数字。程序会根据猜测结果提示用户“大了”或“小了”,直到用户猜对为止,并统计猜测的次数。

程序的主要功能包括:

  • 随机生成1到1000之间的数字
  • 提供用户输入猜测的界面
  • 提示猜测结果
  • 统计并显示猜测次数

这个程序的设计简单直观,用户交互性较强,适合用于学习或娱乐目的。

转载地址:http://wcgnz.baihongyu.com/

你可能感兴趣的文章
Qt读取注册表默认值
查看>>
poj 1679 判断MST是不是唯一的 (次小生成树)
查看>>
POJ 1703 Find them, Catch them
查看>>
POJ 1703 Find them, Catch them 并查集
查看>>
POJ 1738 An old Stone Game(石子合并)
查看>>
POJ 1740 A New Stone Game(博弈)题解
查看>>
Qt网络编程之实例二POST方式
查看>>
POJ 1765 November Rain
查看>>
poj 1860 Currency Exchange
查看>>
POJ 1961 Period
查看>>
POJ 2019 Cornfields (二维RMQ)
查看>>
poj 2057 The Lost House 贪心思想在动态规划上的应用
查看>>
poj 2057 树形DP,数学期望
查看>>
poj 2112 最优挤奶方案
查看>>
Qt编写自定义控件12-进度仪表盘
查看>>
SpringBoot主启动原理在SpringApplication类《第六课》
查看>>
poj 2186 Popular Cows :求能被有多少点是能被所有点到达的点 tarjan O(E)
查看>>
POJ 2186:Popular Cows Tarjan模板题
查看>>
POJ 2229 Sumsets(递推,找规律)
查看>>
poj 2236
查看>>