Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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.

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



  1. The program generates a random number between 1 and 100.

  2. The player is asked to guess the correct number.

  3. The player has a maximum of 15 attempts to guess the correct number.

  4. 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.



  5. 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!