0% found this document useful (0 votes)
9 views20 pages

Anju Cpe 3

The document is a project report on a Number Guessing Game developed in C programming, submitted by Y. Swaranjali for a Bachelor of Technology degree. It outlines the game's objectives, system analysis, implementation details, and proposed enhancements, emphasizing its educational value in teaching programming concepts. The report includes sections on literature survey, system architecture, testing, and future improvements, aiming to create an engaging and interactive user experience.

Uploaded by

kalyanmudiraj16
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views20 pages

Anju Cpe 3

The document is a project report on a Number Guessing Game developed in C programming, submitted by Y. Swaranjali for a Bachelor of Technology degree. It outlines the game's objectives, system analysis, implementation details, and proposed enhancements, emphasizing its educational value in teaching programming concepts. The report includes sections on literature survey, system architecture, testing, and future improvements, aiming to create an engaging and interactive user experience.

Uploaded by

kalyanmudiraj16
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

A

Report on
NUMBER GUESSING GAME

CS109ES- C PROGRAMMING FOR ENGINEERS PROJECT


Submitted in partial fulfilment of the requirements for
The Award of the degree of

BACHELOR OF TECHNOLOGY
In
DEPARTMENT OF ELECTRONICS AND COMMUNICATION
ENGINEERRING
By
Y.SWARANJALI 24K81A04K2
Under the esteemed guidance of

Mr. Nagaraj Rathod


ASSISTANT PROFESSOR
DEPARTMENT OF CSE

DEPARTMENT OF ELECTRONICS AND COMMUNICATION


ENGINEERING
St. MARTIN’S ENGINEERING COLLEGE
UGC AUTONOMOUS
NBA & NAAC A+ Accredited
Dhulapally, Secunderabad – 500100
St. MARTIN’S ENGINEERING COLLEGE
UGC AUTONOMOUS

NBA & NAAC A+ Accredited


Dhulapally, Secunderabad – 500100

College Code: K8
CERTIFICATE
This is certify that the C PROGRAMMING FOR ENGINEERS
entitled “NUMBER GUESSING GAME” is a bonafide record of
independent work done by Y.SWARANJALI (24K81A04K2)under my
supervision and guidance, submitted to St. MARTIN’S
ENGINEERING COLLEGE, Hyderabad, in partial fulfilment for
the award of the Degree of Bachelor of Technology in ELECTRONICS
AND COMMUNICATION ENGINEERING.

Project Internal Guide Head of Department


Mr.Nagaraj Rathod Dr. D.Ranadheer Reddy
(Dept. of CSE) (Dept. of FME)
…………………………….. …………………………………

GROUP DIRECTOR
(Dr. P.SANTOSH KUMAR PATRA)
………………………………………
CONTENTS

ABSTRACT i

CHAPTER 1- INTRODUCTION 1

CHAPTER 2-LITERATURE SURVEY 3

CHAPTER 3-SYSTEM ANALYSIS 5

3.1 Existing System 5

3.2 Proposed System 6

3.3 Hardware Requirements 7

3.4 Software Requirements 7

CHAPTER 4-SYSTEM ARCHITECTURE 10

CHAPTER 5-SYSTEM IMPLEMENTATION 12

CHAPTER 6-SYSTEM TESTING 15

CHAPTER 7-OUTPUT SCREENS 17

CHAPTER 8-CONCLUSION 19

CHAPTER 9-FUTURE ENHANCEMENT 20

CHAPTER 10-REFERENCES 21
ABSTRACT
This project focuses on developing a Number Guessing Game, a simple yet engaging application
aimed at challenging players to guess a randomly generated number within a defined range. The
primary goal is to create an interactive platform that combines entertainment with problem-solving
and logical reasoning.

In this game, the system generates a random number, and the player must deduce the correct
answer through successive guesses. Each guess prompts feedback from the system, indicating
whether the number is too high, too low, or correct. The project can include features such as
adjustable difficulty levels, scoring mechanisms, hints, and a record of attempts to enhance
replayability and user engagement.

The project serves as an educational tool, introducing fundamental programming concepts such as
randomness, user input handling, conditional statements, and loops. It can be expanded to include
multiplayer modes or integrated into educational platforms to encourage learning through
gamification. The Number Guessing Game is a versatile application that appeals to users of all
ages, providing both fun and cognitive challenge.
INTRODUCTION
The " Number the guess" game coded in C is a interactive and engaging console-based program
where the player attempts to identify a randomly generated number between 1 and 100. The game
incorporates dynamic hints that provide the player with guidance during the guessing process.
Feedback includes warmer hints when the guess is within 10 units of the correct number and colder
hints when it is farther away. The program keeps track of the number of attempts, and upon
successfully guessing the secret number, it congratulates the player, revealing the number of
attempts made. This project serves as a practical exercise for C programming beginners,
showcasing the use of random number generation, user input, conditional statements, and loop
constructs to create an entertaining and interactive gaming experience.

WHAT ARE THE CONTROL STATEMENTS USED IN THIS


PROJECT ?

In this C programming project for the “ Number the guess" game, control statements are
pivotal for managing the flow of the game and enhancing user interaction. The primary control
structure employed is the `do-while` loop, ensuring the continuous execution of the game until the
player correctly guesses the secret number. Within this loop, conditional statements, specifically
the `if-else` statements, dynamically evaluate the user's guesses, providing tailored hints based on
whether the guess is too low, too high, warm, or cold. The inclusion of control statements not only
ensures the logical progression of the game but also enhances the user experience by offering real-
time feedback, contributing to the engaging and interactive nature of the project.
OPERATORS USED IN THE PROJECT :-

The "Guess the Number" game implemented in C involves several operators to manage
numerical calculations and comparisons. The modulus operator (`%`) is used to generate a random
number within a specified range, restricting the secret number between 1 and 100. Equality (`==`),
relational (`<`, `>`), and arithmetic (`-`) operators play crucial roles in evaluating the user's guesses
against the randomly generated secret number. These operators determine whether the guess is
correct, too low, or too high, allowing the program to provide appropriate hints to guide the player.
The effective use of these operators enhances the functionality of the game, contributing to its
interactive and dynamic nature.

ARRAYS OR STRINGS OR UNION USED IN THIS PROJECT :-

In the provided " Number the guess" game implemented in C programming, arrays, strings,
structures, and unions are not explicitly utilized. The focus of the project is on simple numerical
comparisons and dynamic user feedback, which does not necessitate the use of more complex data
structures or types. The game primarily relies on basic data types such as integers for storing the
secret number, the user's guesses, and the number of attempts. While additional features or
modifications could introduce arrays or strings for storing multiple secret numbers or custom
messages, the basic version of the game does not incorporate these data structures or types.
LITERATURE SURVEY

ABOUT C & HISTORY OF C LANGUAGE :-

C, a versatile and influential programming language, emerged in the early 1970s at Bell
Labs, designed by Dennis Ritchie as an evolution of the B language. Initially developed for
implementing the Unix operating system, C gained rapid popularity due to its efficiency and low-
level capabilities. The publication of "The C Programming Language" by Brian Kernighan and
Dennis Ritchie in 1978 solidified its status as a programming staple. Standardized as ANSI C in
1989 and subsequently as ISO C in 1990, the language's consistent standards ensured portability
and widespread use. C's influence extended to subsequent languages like C++, Objective-C, and
C#. Its evolution, with revisions like C99 and C11, maintained its relevance by introducing new
features. Known for its simplicity and close-to-hardware capabilities, C remains a foundational
language for systems programming and software development, embodying a rich history and
enduring significance in the computing world.

WHAT ARE C TOKENS & TOKENS USED IN THIS PROJECT :-

In C programming, tokens are the smallest units in the source code, and they are the
building blocks of a program. Common C tokens include keywords, identifiers, constants,
operators, and punctuation symbols. In the " Number the guess" game project, the code involves
several types of tokens:

1. Keywords: Words reserved by C that convey specific meanings. Examples include `int`, `
do`, ` while`, `if`, and `else`.
2. Identifiers: Names given to variables and functions. In the project, `main`, `
secret Number`, guess `and `attempts` are examples of identifiers.

3. Constants: Fixed values used in the program. In this project, numeric constants

4. Operators: Symbols that perform operations on variables and values.

Common operators in the project include `=`, `==`, `%`, `<=`, `<`, `>`, and `-`.
DATA TYPES USED IN THIS PROJECT :-

In the " Number the guessr" game project implemented in C, several fundamental data
types are utilized to store and manipulate different kinds of information. The primary data type
used in this project is:

1. Integer (int): The `int` data type is employed to represent whole numbers. In this project, `int`
is used for variables such as `secret Number`, `guess`, and `attempts` to store the randomly
generated secret number, user input for guesses, and the count of attempts made by the player.

Additionally, the `abs()` function is used to calculate the absolute difference between the user's
guess and the secret number, returning a positive integer. The `srand()` and `time()` functions
involve the `unsigned int data type, which is implicitly used in the project for seeding the random
number generator based on the current time.
SYSTEM ANALYSIS

EXISTING SYSTEM & DIS-ADVANTAGE :-

The " Number the guess" game implemented in C doesn't necessarily have a distinct existing
system, as it's a relatively simple console-based application. However, we can discuss potential
drawbacks or limitations associated with the current implementation:
1. Simplicity: The existing system is intentionally kept simple for educational purposes. While
simplicity is beneficial for learning, it might be a disadvantage if the goal is to create a more
feature-rich and visually appealing game.

2. Text-Based Interface: The game operates in a console environment with a text-based interface.
This could be considered a limitation for users who prefer more graphical or interactive interfaces
found in modern games.

3. Limited User Engagement: The project focuses on basic gameplay mechanics and feedback. To
enhance user engagement, future iterations could incorporate graphics, sound effects, or additional
gameplay elements to make the experience more immersive.

4. Single Player Only: The current implementation supports only a single player. Expanding the
game to include multiplayer functionality or additional game modes could make it more versatile
and entertaining.

5. Predictable Hints: The hints provided in the game are deterministic based on the absolute
difference between the guess and the secret number. Introducing more dynamic and varied hinting
mechanisms could make the game more interesting.

6. Limited Randomness: The random number generation is based on the `rand()` function, which
might not be truly random. In a more advanced project, a more sophisticated random number
generator could be employed to ensure better unpredictability.

7. Lack of Persistence: The game does not save high scores or user progress. Adding a feature to
save and display high scores over multiple sessions could increase replay value.
PROPOSED SYSTEM & ADVANTAGES:-

The proposed system for the " Number the guess" game aims to enhance user experience by
introducing a graphical user interface, multiplayer support, varied difficulty levels, sound effects,
animations, a persistent high-score system, dynamic hinting mechanisms, improved random
number generation, and robust error handling. These features collectively elevate the game,
making it visually appealing, socially engaging, and dynamically challenging. The graphical
interface and multimedia elements create a more immersive atmosphere, while the addition of
multiplayer functionality and difficulty levels cater to a diverse audience.

SOFTWARE REQUIREMENTS :-

The software requirements for the " Number the guess" game project include a C compiler such as
GCC, Visual C++, or Clang for code translation, an integrated development environment (IDE)
like Code::Blocks or Visual Studio Code for code editing, and an operating system such as
Windows, Linux, or macOS. The project may utilize the standard C library's `rand()` function for
random number generation, and optionally, version control systems like Git for code management
and documentation tools like for generating documentation. These tools collectively form the
development environment necessary for creating, compiling, and managing the "Guess the
Number" game code.

HARDWARE REQUIREMENTS:-

The " Number the guess" game implemented in C has minimal hardware requirements. Any
standard personal computer or laptop with a compatible operating system (such as Windows,
Linux, or macOS) is sufficient. The hardware specifications should meet the basic requirements
for running the chosen C compiler and development environment. These typically include a
processor with reasonable speed, sufficient RAM for compiling and running the code, and
adequate storage space for the development tools and project files. Given the simplicity of console-
based game, no specialized or high-end hardware components are necessary, making it accessible
on a wide range of computing devices.
FLOWCHART
ALGORITHM

1. Initialize Variables:
- Initialize secret Number, guess, and attempts as integers.

2. Generate Random Number:


- Use a random number generator to generate a random number between 1 and 100, and store
it in secret Number.

3. Display Welcome Message:


- Print a welcome message explaining the game rules to the user.

4. Game Loop:
- Start a loop for the player to make guesses.
a. Prompt User for Guess:
- Print a prompt asking the user to input their guess.
b. Get User Input:
- Read the user's input for the guess.
c. Check Guess:
- Compare the user's guess with secretNumber.
d. Provide Hints:
- Based on the comparison, print hints such as "Too high," "Too low," "Warm," or "Cold."
e. Increment Attempts:
- Increment the attempt count.
f. Check for Correct Guess:
- Check if the guess is correct. If yes, exit the loop.
g. Repeat Loop:
- Return to the beginning of the game loop.

5. Game Over:
- Exit the loop when the correct number is guessed.

6. Display Congratulations Message:


- Print a congratulatory message along with the number of attempts it took to guess the
correct number.

7. End:
- End the program.
SYSTEM IMPLEMENTATION
CODE OF THE PROJECT :-

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main() {
// Seed the random number generator
srand(time(NULL));

// Generate a random number between 1 and 100


int secretNumber = rand() % 100 + 1;

int guess;
int attempts = 0;

printf("Welcome to the Guess the Number game!\n");


printf("Try to guess the number between 1 and 100.\n");

do {
// Get user input
printf("Enter your guess: ");
scanf("%d", &guess);

// Increment the attempts counter


attempts++;

// Check if the guess is correct


if (guess == secretNumber) {
printf("Congratulations! You guessed the number in %d attempts.\n", attempts);
break;
} else if (guess < secretNumber) {
printf("Too low! Try again.\n");
} else {
printf("Too high! Try again.\n");
}

} while (1); // Infinite loop until the correct guess is made

return 0;
}
MODULES/FUNCTIONS USED :-

In a simple console-based "Guess the Number" game implemented in C, you can organize the code
into several functions or modules to enhance readability, modularity, and maintainability. Below
are example modules/functions that are used in this project -
1. main Function:
- The main entry point of the program. It initializes the game, calls other functions, and manages
the overall flow of the game.

2. initialize Game Function:


- Initializes variables such as `secret Number`, `guess`, and `attempts`. It can also be responsible
for generating the initial random number.

3. display Welcome Message Function:


- Prints a welcome message to the user, explaining the rules and how to play the game.

4. get User Input Function:


- Prompts the user for input and reads the user's guess. It may include input validation to ensure
that the input is a valid number.

5. provide Hint Function:


- Takes the user's guess and the secret number as input and provides hints such as "Too high,"
"Too low," "Warm," or "Cold."

6. check Winning Condition Function:


- Checks if the user's guess matches the secret number, indicating a correct guess and ending the
game.

7. display Results Function:


- Displays a congratulatory message along with the number of attempts when the player correctly
guesses the number.

8. game Loop Function:


- Implements the main loop of the game, where the player can make multiple guesses until the
correct number is guessed. It calls other functions like `getUserInput`, `provideHint`, and `check
Winning Condition`.
SYSTEM TESTING

Test 1:

Test 2:
OUTPUT SCREENS

here the code is executed & input is given as 6 but the guess was too low so the output is given
as “too low ! try again”.

As the input was given as 6 previously , now the input is given a s 9 & the output is given as too
low! try again.
here the input is given as 65 & the output is given as too low again .
hence we can conclude from the 3 output images that the code works perfectly.
CONCLUSION
In solving the "Number the guess" project, I employed a modular approach, defining functions like
`initialize Game`, `display Welcome Message`, `get User Input`, `provide Hint`, `check Winning
Condition`, and `display Results` to organize the code logically. The `main` function orchestrates
the overall game flow. This approach enhances code readability, maintainability, and modularity,
making it easier to understand and modify the code in the future.

The " Number the guess" game, while a simple project, can be educational and entertaining. It can
be used as a beginner-friendly introduction to programming concepts such as random number
generation, user input, control flow, and modular design. Beyond its educational value, simple
games can be used to promote problem-solving skills and cognitive development, making them
beneficial for individuals learning to code. Additionally, such projects can serve as a stepping stone
for more complex game development endeavors, fostering creativity and technical skills in
aspiring program.
FUTURE ENHANCEMENTS

The provided code for the " Number the guess" game, while serving as a fundamental introduction,
lacks several advanced features. Notably, a graphical user interface (GUI) has not been
implemented, limiting the game to a console-based interaction. Multiplayer support is absent,
denying users the ability to compete or collaborate. The absence of difficulty levels restricts player
customization, and there's a lack of sound effects and animations for a more immersive experience.
Persistent high scores, dynamic hinting mechanisms, and improved random number generation
remain unaddressed, impacting competitiveness and gameplay variety. Additionally, the code lacks
extensive error handling and input validation, potentially affecting user interactions. A more user-
friendly menu system and an enhanced game over screen could contribute to a more polished
overall experience. Addressing these goals would elevate the game, offering users a richer and
more engaging gaming environment.
REFERENCES

1. GeeksforGeeks

Reference: "Number Guessing Game in C"

URL: GeeksforGeeks

Description: Offers practical code examples and logic explanations for beginners and advanced
users.

2. Scaler Topics

Reference: "Building a Number Guessing Game in C"

URL: Scaler

Description: Focuses on step-by-step project development and optimization.

3. Programming with Harry

Reference: "Number Guessing Game Code in C"

URL: Programming with Harry

Description: A blog offering creative insights and sample projects.

4. "Random Number Generators: Theory and Practice" by George Marsaglia

Description: Explores random number generation techniques, crucial for number guessing
games.

5. "Game-Based Learning in Programming" by William H. Watson et al.

Published in: International Journal of Game Design

Description: Discusses how games can enhance learning programming concepts.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy