A console-based Hangman word-guessing game written in C++.
| Menu & Rules | Gameplay |
|---|---|
![]() |
![]() |
This project was developed as a Programming Fundamentals coursework assignment at NASTP Institute of Information and Technology (NIIT), a constituent of Air University. It demonstrates core C++ programming concepts through an interactive console game where the player guesses a hidden word letter by letter before running out of lives.
- Three difficulty levels — Easy, Medium, and Hard
- Three word categories per level — Animals, Nature, Fruits, Cities, Countries, Space, Sports
- ASCII art hangman — visual progression as lives are lost
- Input validation — handles invalid menu selections and non-numeric input gracefully
- Duplicate guess detection — warns when a letter has already been guessed
- In-game rules — accessible from the difficulty selection menu (option 4)
- Replay option — play multiple rounds without restarting the program
- The player is welcomed and selects a difficulty level (Easy, Medium, or Hard).
- Within the chosen difficulty, the player picks a word category.
- A random word from that category is selected and displayed as underscores.
- The player guesses one letter at a time. Correct guesses reveal matching positions; incorrect guesses cost one life.
- The player starts with 5 lives. An ASCII hangman figure builds up with each wrong guess.
- The game ends when the word is fully revealed (win) or all lives are lost (lose).
- After each round, the player can choose to play again.
- C++ Standard Library:
<iostream>,<vector>,<algorithm>,<cstdlib>,<ctime>,<limits> - Windows console I/O:
<conio.h>forgetch() - Functions and forward declarations
std::vectorandstd::stringstd::findfor searching containersswitchstatements and nesteddo…whileloops- Input validation with
cin.fail(),cin.clear(), andcin.ignore() - Pseudo-random number generation with
srand()andrand() - Menu-driven console interface
- Operating system: Windows
- Compiler: Any C++ compiler that provides
<conio.h>— for example:- MinGW (g++ for Windows)
- Microsoft Visual C++ (MSVC)
Note: This project uses
<conio.h>andgetch(), which are Windows-specific. It will not compile on Linux or macOS without modification.
Using g++ (MinGW):
g++ hangman.cpp -o hangman.exe
hangman.exeUsing MSVC (Developer Command Prompt):
cl hangman.cpp
hangman.exe- Run the program and press any key to start.
- Enter
4at the difficulty menu to read the rules (optional). - Select a difficulty level:
1(Easy),2(Medium), or3(Hard). - Select a word category:
1,2, or3. - Guess letters one at a time — use lowercase letters.
- You have 5 lives per round.
- After the round ends, enter
yto play again ornto quit.
cpp-hangman-game/
├── docs/
│ └── screenshots/ # Gameplay screenshots
├── hangman.cpp # Complete game source code
├── .gitignore # C++/Windows build artifact exclusions
└── README.md # This file
- Windows only — depends on
<conio.h>/getch()for the initial keypress prompt. - Lowercase input only — guesses must be entered in lowercase to match the word lists.
- Single-character input — the game reads one character per guess; entering multiple characters may leave extra input in the buffer.
- Hardcoded word lists — words are defined directly in the source code rather than loaded from an external file.
- Fixed lives — all difficulty levels use the same number of lives (5).
Muhammad Umer Iqbal Programming Fundamentals — NASTP Institute of Information and Technology (NIIT), Air University
This project was created as an academic exercise to demonstrate foundational C++ programming skills.

