当前位置:网站首页>Guess the number / / generate a random number for the first time
Guess the number / / generate a random number for the first time
2022-07-29 07:06:00 【Meat loving Xiaobai】

The code is as follows :
#include<iostream>
#include<ctime>// The function uses the current system time to generate random numbers , Prevent random numbers from being the same
using namespace std;
int main(void)
{
srand((unsigned int)time(NULL));
int num = rand() % 100 + 1;
cout << " Please enter 0 - 100 The random number guessed by :";
int num2;// The user enters the created variable
int num3 = 0;
while (1)
{
cin >> num2;
if (num2 > num)
{
cout << " Small handkerchief , The guessed number is greater than the random number :";
num3++;
}
else if (num2 < num)
{
cout << " Small handkerchief , The guessed number is less than the random number :";
num3++;
}
else
{
cout << " It was used "<< num3 <<" Second guess right , Small handkerchief , No way !";
break;//break Used to skip the loop
}
}
return 0;
}
边栏推荐
- Cvpr2022oral special series (I): low light enhancement
- [C language brush leetcode] 1054. Bar code with equal distance (m)
- 记 - 踩坑-实时数仓开发 - doris/pg/flink
- Talk about tcp/ip protocol? And the role of each layer?
- 基于C语言实现图书借阅管理系统
- 【C语言刷LeetCode】1054. 距离相等的条形码(M)
- 数据库使用psql及jdbc进行远程连接,不定时自动断开的解决办法
- 外包干了3年,跳槽后转自动化测试工资是原来的2倍,秘诀原来是......
- 330. 按要求补齐数组
- Flink real time warehouse DWD layer (traffic domain) template code
猜你喜欢
随机推荐
我的创业邻居们
Teacher wangshuyao's notes on operations research 03 KKT theorem
Ali gave several SQL messages and asked how many tree search operations need to be performed?
聊天机器人有何用处?有何类型?看完这些就明白了!
MySQL: what happens in the bufferpool when you crud? Ten pictures can make it clear
Simulation volume leetcode [normal] 222. number of nodes of complete binary tree
Flink real time warehouse DWD layer (traffic domain) template code
[C language brush leetcode] 2332. The latest time to get on the bus (m)
Simulation volume leetcode [normal] 081. Search rotation sort array II
Some tips of vim text editor
Cesium反射
Teacher wangshuyao's notes on operations research 05 linear programming and simplex method (concept, modeling, standard type)
Can MySQL export tables regularly?
Image noise and matrix inversion
基于C语言实现图书借阅管理系统
Database multi table query joint query add delete modify query
MySQL:当你CRUD时BufferPool中发生了什么?十张图就能说清楚
线程 - 线程安全 - 线程优化
Summary of 2022 SQL classic interview questions (with analysis)
模拟卷Leetcode【普通】093. 复原 IP 地址









