This project implements a number guessing game in the C programming language, designed to reinforce fundamental programming concepts.
The game randomly generates a 4-digit secret number (between 1000 and 9999), and the player has 10 attempts to guess it correctly.
After each guess, the program provides feedback on how many digits are correct and in the correct position.
Starting from the fifth attempt, the game introduces progressive hints to assist the player, such as digit parity (even/odd) and comparison to the number 5.
At the end of each round, the player can choose to restart or exit the game.
Developed by João Paulo Nunes Andrade, Caíque Andraus, Gabriel Oliveira, and João Victor Neder.
- 🔢 Secret Number Generation – Uses
rand()andsrand(time(NULL))from<stdlib.h>and<time.h>to generate a random 4-digit number - 🎯 Limited Attempts – Players have up to 10 chances to guess the correct number
- 📊 Feedback System – Displays how many digits are correct and in the correct position after each guess
- 💡 Hint System – From the 5th attempt onward, provides hints such as:
- Parity (even or odd)
- Comparison (greater than or less than/equal to 5)
- 🎨 Interactive Interface – Uses ANSI color macros (
#define RED,#define GRN,#define YEL) to highlight messages and improve user experience - 🔁 Restart Option – Allows the player to choose whether to play again after each game
- Language: C (standard libraries only)
- Digit Manipulation: Uses division (
/) and modulo (%) to extract and compare digits - Control Structures:
if,while,do-whilefor game logic and input validation - Localization:
setlocale(LC_ALL, "Portuguese")from<locale.h>for proper character display - Console Management:
system("cls")andsystem("pause")for screen clearing and user flow (OS-dependent)
- Save the code as
game.c - Compile using GCC:
gcc game.c -o game