Skip to content

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.

Notifications You must be signed in to change notification settings

arezyhs/cplusplus-number-guessing-game

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

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!

About

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.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages