https://github.com/misaghmomenib/number-guessing-game-cpp
The Number Guessing Game is a simple C++ console-based application where the player tries to guess a randomly generated number within a specific range. The game provides hints such as "Too High" or "Too Low" after each incorrect guess to help the player narrow down the correct number.
https://github.com/misaghmomenib/number-guessing-game-cpp
cpp git number-guessing-game open-source
Last synced: 2 months ago
JSON representation
The Number Guessing Game is a simple C++ console-based application where the player tries to guess a randomly generated number within a specific range. The game provides hints such as "Too High" or "Too Low" after each incorrect guess to help the player narrow down the correct number.
- Host: GitHub
- URL: https://github.com/misaghmomenib/number-guessing-game-cpp
- Owner: MisaghMomeniB
- Created: 2025-02-01T07:25:56.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-06-13T21:03:11.000Z (about 1 year ago)
- Last Synced: 2025-06-13T22:18:59.420Z (about 1 year ago)
- Topics: cpp, git, number-guessing-game, open-source
- Language: C++
- Homepage:
- Size: 35.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ๐ฏ Number Guessing Game (C++)
A fun and interactive **console-based number guessing game** implemented in modern C++. Ideal for beginners to learn random number generation, loops, conditionals, input validation, and basic game logic.
---
## ๐ Table of Contents
1. [Overview](#overview)
2. [Features](#features)
3. [Tech Stack & Requirements](#tech-stack--requirements)
4. [Installation & Build](#installation--build)
5. [Usage Examples](#usage-examples)
6. [Code Structure](#code-structure)
7. [Extendability Ideas](#extendability-ideas)
8. [Contributing](#contributing)
9. [License](#license)
---
## ๐ก Overview
This CLI game randomly selects a number (e.g., between 1โ100) and challenges the player to guess it within a limited number of attempts. Feedback is provided after each guess ("too high"/"too low") to guide the player. A classic exercise to practice foundational C++ concepts. :contentReference[oaicite:1]{index=1}
---
## โ
Features
- ๐ฒ Random number generation using `rand()` seeded with current time
- โฑโโ๏ธ Difficulty levels offering different attempt limits (e.g., Easy/Medium/Hard)
- ๐ Feedback loop: informs player if guess is too high or too low
- ๐งฎ Input validation to handle non-numeric user entries
- ๐ Win/lose messages, with option to replay
- ๐
Tracks and displays total wins and losses in a session
---
## ๐ ๏ธ Tech Stack & Requirements
- **C++11+** compatible compiler (`g++`, `clang++`, or MSVC)
- Standard Headers:
- `` for I/O
- `` and `` for randomization
- `` for input validation
---
## โ๏ธ Installation & Build
Clone the repository and compile:
```bash
git clone https://github.com/MisaghMomeniB/Number-Guessing-Game-Cpp.git
cd Number-Guessing-Game-Cpp
g++ -std=c++11 -o guess_game main.cpp
````
Or, if using CMake:
```bash
mkdir build && cd build
cmake ..
make
```
---
## ๐ Usage Examples
Run the game with:
```bash
./guess_game
```
Typical session flow:
```
Welcome to the Number Guessing Game!
Choose difficulty (1=Easy, 2=Medium, 3=Hard): 2
I'm thinking of a number between 1 and 100. You have 7 guesses.
Enter your guess: 50
Too high! 6 guesses left.
...
Congratulations! You guessed the number in 5 attempts.
Play again? (y/n): y
```
Tracks and displays the session's win/loss record upon exit.
---
## ๐ Code Structure
```
Number-Guessing-Game-Cpp/
โโโ main.cpp # Game logic, RNG, input loop, and scoring
```
Key components:
* RNG seeded with `time(0)`
* Difficulty-level selection setting guess limits
* Input validation using `cin.clear()` and `cin.ignore()`
* Loop controlling guesses with feedback and replay option
---
## ๐ก Extendability Ideas
* ๐ง Add customizable range or difficulty command-line flags
* โณ Integrate timer to track completion time
* ๐ Maintain user-specific high scores (file I/O)
* ๐จ Add ASCII art or colorful output to enhance UX
* ๐งช Add unit tests with frameworks like Catch2
---
## ๐ค Contributing
Contributions are welcome! To add features or enhancements:
1. Fork the repository
2. Create a feature branch (e.g., `feature/highscores`)
3. Document and comment your code
4. Submit a Pull Request for review
---
## ๐ License
Released under the **MIT License** โ see `LICENSE` for full details.