Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to achieve simple number guessing on C++ Mini Game

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

In this article, the editor introduces in detail "how C++ realizes simple number guessing Mini Game". The content is detailed, the steps are clear, and the details are handled properly. I hope this "C++ how to achieve simple number guessing Mini Game" article can help you solve your doubts. Let's follow the editor's ideas slowly and deeply, together to learn new knowledge.

1. Random number

In this paper, time (0) is used as the seed generated random number of srand () function, and time (0) is the number of seconds from 00:00:00 to this time on January 1, 1970. In this paper, the random number range is controlled at 0,100, which can be changed according to your own needs.

Number of times

Times represents the number of times in the code of this article, which can be changed according to your own needs.

III. Conditions for winning or losing

The correct guess of the number is a victory, and it is a failure if you do not guess right before the number of times is exhausted. Please enter 1 to continue playing after the end, and enter any other characters to exit the game. (this article sets the game to start after entering the correct range of numbers, and entering the wrong range of numbers will still reduce the number of times.)

Code # include#include#includeusing namespace std;int main () {int num1 = 0; int num2 = 0; int num3 = 1; int times = 7; while (num3 = = 1) {times = 7; srand ((unsigned int) time (NULL)); num1 = rand ()% 100; cout

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report