Guess The Number Game Report

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 17

A PROJECT REPORT OF 6TH Semester

BACHELOR OF TECHNOLOGY
IN
Computer Science and Engineering

SUBMITTED BY:

Ruchi Kumari (2006319)

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

QUEST INFOSYS FOUNDATION GROUP OF INSTITUTIONS, JHANJERI


Feb-May, 2023
Abstract

The "Guess the Number" game is a popular and interactive game that involves a player trying to guess
a randomly generated number within a given range. This project aims to implement the "Guess the
Number" game in the C++ programming language.

The game involves the generation of a random number within a specified range, and the player is
given a certain number of attempts to guess the correct number. The program will provide hints to the
player, indicating whether their guess is too high or too low. The player's objective is to use these
hints to refine their guesses and ultimately arrive at the correct number.

The implementation of the game utilizes fundamental programming concepts such as random number
generation, user input, conditional statements, loops, and basic arithmetic operations. The user
interface is designed to be intuitive and user-friendly, allowing the player to easily interact with the
program and enter their guesses

ii
Acknowledgement

I would like to express my deepest gratitude and appreciation to all those who have contributed
to the successful completion of the Bank Management project and the preparation of this project
report.

First and foremost, I would like to thank my supervisor Miss. Rubbina Sheikh, for their
invaluable guidance, support, and expertise throughout the duration of this project. Their
continuous encouragement, insightful feedback, and constructive criticism have been
instrumental in shaping the direction and quality of this work.

I would also like to extend my sincere thanks to the faculty and staff of Quest Group of
Institution, whose knowledge and resources provided a solid foundation for this project. The
access to the necessary infrastructure and software facilities was crucial in carrying out the
research and development work effectively.

I would like to thank everyone who has contributed to the completion of this project(indirectly).
Your support, guidance, and encouragement have been invaluable, and I am truly grateful for the
opportunity to work on this project.
Thankyou.

Ruchi Kumari

iii
List of Figures

Fig. No Title Page No.


1.0 Welcome Screen 10
1.1 Enter the Guess 10
1.2 Press Enter to Play the Game 11
1.3 Give Hints to Guess the Number Right 11

iv
Contents
Topic Page No.
Certificate by Institution i

Abstract ii

Acknowledgement iii

List of Figures iv

Chapter 1 : Introduction to C++ 1-2

Chapter 2 : Introduction to Guess The Number Game Project 3


Chapter 3 : Implementation & Source Code 6-9
Chapter 4 : Output 10-11
References 12

v
Chapter 1 : Introduction to C++

C++ is a general-purpose programming language that was developed in the early 1980s as an

extension of the popular C programming language. It was designed to provide additional features and

capabilities while maintaining compatibility with C. C++ is known for its efficiency, flexibility, and

performance, making it a popular choice for a wide range of applications, including system software,

game development, embedded systems, and high-performance computing.

One of the key features of C++ is its support for object-oriented programming (OOP). It allows

developers to organize their code into reusable and modular objects, which encapsulate data and

behavior. This enables the creation of complex software systems with clear structures and easier

maintenance.

C++ also includes support for generic programming, which allows the development of algorithms and

data structures that can be used with different data types. This is achieved through the use of

templates, which enable the creation of generic classes and functions.

Another notable feature of C++ is its emphasis on performance. It provides low-level control over

hardware resources and supports features such as direct memory manipulation and inline assembly

code. This makes C++ suitable for applications that require high efficiency and fine-grained control

over system resources.

C++ is a statically-typed language, meaning that the type of each variable is known at compile-time.

1
This helps catch many errors early in the development process and can lead to more robust and

efficient code.

Over the years, C++ has evolved through different versions, with each version introducing new

features and enhancements. The most recent standard is C++17, released in 2017, followed by C++20

in 2020. These standards have introduced improvements in areas such as language syntax, libraries,

and concurrency support.

2
Chapter 2 : Introduction to Guess the Number Game Project

The Guess the Number game is a simple game where the user tries to guess a randomly generated
number within a given range. The game is implemented in C++ and involves a computer program
generating a random number and then prompting the user to guess what the number is. The game
provides feedback to the user indicating if their guess is too high, too low or if they have guessed
correctly.

The Guess the number Game will be implemented using C++ programming language. The
system will have a console-based user interface that will allow user to interact with the Game.

The Guess the Number game will have the following features:

Random number generation: The game will generate a random number within a given range.
User input: The user will be able to input their guess.
Feedback: The game will provide feedback to the user indicating if their guess is too high, too low, or
correct.
Game loop: The game will continue until 10 moves to guess correct number.

3
Implementation

The Guess the Number game will be implemented using the C++ programming language. The game
will use the srand function to seed the random number generator with the current time. The rand
function will be used to generate a random number within the range of 1 to 100. The game will use a
loop to prompt the user for their guess and provide feedback until 10 moves to user have to guessed the
correct number in 10 moves. The game will also validate user input to ensure that the input is a valid
integer within the range of 1 to 100.

In this implementation, we first use the random number generator with the current time using
srand(time(0)). This ensures that we get a different random number each time we run the program. We
then generate a random number between 1 and 100 using rand() % 100 + 1.

We then Enter for loop where we prompt the user to guess a number between 1 to 100.We also keep
track of moves by I variable.

After Each Guess, we check if the guess is too low,too high,or equal to the generated number using an
if else statement.

The loop continues until the user guesses the correct number or until 10 moves at which point the loop
terminates and the program end. The output is based on user. If user guess correct generated number
then output is
“congratulation ,you guessed it right” or If 10 moves are over then
Output is your Moves are over Game over.

This is Function of Game which has void return type. In this game function is called in main Function
because compiler always call main function and without main function game function can not be executed.

About Instruction function:-This Function is welcome Screen of the game. In this Function we just print

4
rules and about the game. Design of home screen by print method stored in iostream library.

Overall, this implementation of the guess the number game in C++ is simple and easy to understand. It uses
basic input and output functions, as well as a for loop to repeat the guessing process until the user guesses
correctly.

5
Chapter 3 : Source Code

// **************** Guess the Number Name Project **********************

#include<iostream.h>

#include<cstdlib>

#include<conio.h>

#include<ctime>

using namespace std;

void instruction(){

cout<<"\n"<<"\t"<<"Welcome to"<<endl;

cout<<"\t"<<"the Guess the Number Game!!"<<endl;

cout<<endl;

cout<<"\t"<<"\t"<<"INSTRUCTION"<<endl;

cout<<endl;

cout<<":> You have to guess a number between 1 and 100."<<endl;

cout<<"It create Random Number between 1 to 100 and you have to guess it"<<endl;

cout<<"if your guess is high then it will tell(you guess is high"

<<",please try again)"<<endl;

cout<<"and if your guess is lower"<<" than the number then it"

<<" will tell (your guess is lower than the number.This is"

<<" the Hint to guess the right number.It has only 10 limited"

<<" moves"<<endl;
6
cout<<"\n"<<"Press any to start the Game!!"<<endl;

getch();

void game()

cout << "\t \t \t \t";

cout << "Guess the Number Game" << endl;

cout << "\n";

cout << "\n";

cout << "\n";

cout << "\n";

cout << "\t \t \t Ready to Play The Game. Press 'Enter";

getch();

system("cls");

int digit, guess,i;

srand(time(0));

digit = rand() % 100 + 1;

cout << "\t \t \t \t";

cout << "Guess the Number Game" << endl;

cout << "\n";

cout << "\n";

cout << "\n";

for (i = 0; i != 10; i++)

7
{

printf("Guess the Number between 1 to 100\n");

scanf("%d", &guess);

if (guess > 100)

cout << "Not in the Range\n";

break;

if (guess < 0)

cout << "Not in the range";

break;

if (guess < digit)

cout << "your guess is low,please try again\n";

else if (guess > digit)

cout << "you guess is high,please try again\n";

8
else

cout << "congratulation,you gueesed it right\n";

break;

return;

if(i==10){

system("cls");

cout<<"Your Moves are over"<<endl;

cout<<"\n"<<endl;

cout<<"\t"<<"Game over"<<endl;

int main(){

system("cls");

instruction();

system("cls");

game();

9
Chapter 4 : Output

Fig 1.0: Welcome Screen

10
Fig1.1:Press Enter to Play the Game

Fig1.2:Enter Your Guess.

Fig 1.3:Give Hints to Guess the Number Right

11
References

[1] Code With Harry

https://www.codewithharry.com/tutorial/cplusplus/

[2] C++ for Beginners : A Step-by-Step Guide on Programming Language with Practical Explanations

[3] Geek for Geeks

https://www.geeksforgeeks.org/c-plus-plus/

12

You might also like