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

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.

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.