Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
SUBMITTED BY:
T.AKASH
S.VIGNESH
M.SYED MOHAMED
D.PRATHIK KAMAK
BRIEF DESCRIPTION:
The game is a single player game called “Number
guessing name“.
It is an easy game where the player find it interesting
to play.
HOW TO PLAY:
The computer chooses a random number within a
known range.
The player tries to guess the number.
If the guess is incorrect, then the computer tells the
whether the guess was too high or too low.
Eventually, the player guesses the correct number.
The key strategy in this game is to generate a clever
guess.
ALGORITHM:
Algorithms are the set of rules that
define how a particular problem can be
solved in finite number of steps.
A program is the expression of an
algorithm in a programming language.
REPRESENTATION OF AN ALGORITHM:
Normal English
Program
Flowchart
Pseudo code
Decision Table.
ALGORITHM:
STEP 1: Start.
Step 7:stop
FLOWCHART:
Flowchart is a pictorial
representation of step by a step solution of
a problem.
FLOWCHART:
Start
Enter a number
between 1-10
Willing to yes
play again
no
Stop
PROGRAMMING CODE:
#include <iostream>
#include <stdlib.h>
#include <time.h>
#include <cstdlib>
#include <windows.h>
using namespace std;
int main()
{
int userInput;
int number;
int min = 1;
int max = 10;
float playerTimesToPlay = 0;
int playAgain;
float tries = 3;
do
{ system("CLS");
cout << "Welcome to my number guessing game!" << endl;
cout <<
"===================================================
=" << endl;
cout << "The computer is generating a number between 1 and
10." << endl;
cout <<
"===================================================
=" << endl;
srand(time(0));
number = rand()% (max - min + 1)+min;
playerTimesToPlay = 0;
tries = 3;
do
{
cout << "Please take a guess: ";
if (!(cin >> userInput))
{cout << endl;
cout << "Please enter numbers only." << endl;
cin.clear();
cin.ignore(10000,'\n');
}
while(userInput > 10 || userInput < 0)
{
cout << "Pick a number BETWEEN 1 TO 10." << endl;
cout << endl;
userInput = NULL;
playerTimesToPlay=0;
}
tries--;
cout << endl;
cout << "You picked: " << userInput << endl;
cout << "======================" << endl;
playerTimesToPlay++;
if(userInput != number && tries > 0 && userInput <= 10)
{
cout << "Sorry! Invalid choice. Please try again. You have " <<
tries << " guess(es) remaining." << endl;
cout << endl;
}
else if(userInput != number && tries == 0)
{
cout << "Sorry! Invalid choice." << endl;
cout << "You have " << tries << " guesses remaining. You lose."
<< endl;
cout << endl;
cout << "Play again? " << endl;
cout << "1. Yes" << endl;
cout << "2. No" << endl;
cout << ": " ;
cin >> playAgain;
}
if(userInput == number)
{
cout << "Congratulations! You guessed the correct number!" <<
endl;
cout << "Thanks for playing!" << endl;
Sleep(2500);
}
}
while (playerTimesToPlay < 3 && userInput != number);
}
while (playAgain == 1);
system("Pause(0)");
return 0;
}
EXECUTION
OUTPUT:
-----------X-----------