Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/arezyhs/cplusplus-number-guessing-game
This C++ program is a simple number guessing game. The program generates a random number between 1 and 100, and the player's task is to guess the correct number within a limited number of attempts.
https://github.com/arezyhs/cplusplus-number-guessing-game
cplusplus guess-the-number
Last synced: about 1 month ago
JSON representation
This C++ program is a simple number guessing game. The program generates a random number between 1 and 100, and the player's task is to guess the correct number within a limited number of attempts.
- Host: GitHub
- URL: https://github.com/arezyhs/cplusplus-number-guessing-game
- Owner: arezyhs
- Created: 2023-10-29T11:15:07.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2023-10-29T11:16:54.000Z (about 1 year ago)
- Last Synced: 2023-10-30T11:23:28.650Z (about 1 year ago)
- Topics: cplusplus, guess-the-number
- Language: C++
- Homepage:
- Size: 3.91 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Number Guessing Game
Description
This C++ program is a simple number guessing game. The program generates a random number between 1 and 100, and the player's task is to guess the correct number within a limited number of attempts.
How to Play
- The program generates a random number between 1 and 100.
- The player is asked to guess the correct number.
- The player has a maximum of 15 attempts to guess the correct number.
- After each guess, the program provides feedback:
- If the guess is lower than the correct number, it displays "terlalu kecil" (too small).
- If the guess is higher than the correct number, it displays "terlalu besar" (too big).
- If the guess is correct, it displays "Selamat! Tebakan anda benar!" (Congratulations! Your guess is correct!), and the game ends.
- If the player runs out of attempts without guessing the correct number, the program displays the correct answer and a message: "Maaf, kesempatan kamu habis. Jawaban yang benar adalah: [correct number]."
How It Works
- The program uses the
srand
function to seed the random number generator based on the current time, ensuring a different random number each time you run the program. - It generates a random number (
nilaiBenar
) between 1 and 100. - The player's guesses (
nilaiTebakan
) are compared to the correct number. - The player is given a maximum of 15 attempts to guess the correct number.
- The program provides feedback based on the player's guesses and eventually informs if the guess is correct or if the player has run out of attempts.
Note
- This program is a simple demonstration of a number guessing game and can serve as an educational and entertaining code example for beginners learning C++.
- You can modify the number range and the maximum number of attempts by changing the constants in the code to customize the game.
Enjoy playing and learning with this number guessing game!