Produce a complete C++ game that resembles the “Hang Man Game”, where the player is required to guess a given number/character/word. The player will be given a limited number of guesses. Each time the wrong answer is given, display an appropriate figure that changes accordingly. You may refer to the following diagrams as an example:


1st guess 2nd guess 3rd guess 4th guess Last/End

Allow tips/hints to be given each time the guess is wrong. For example, tell the player that the mystery number is higher or lower than the wrong number given by the player or display the correct characters from the guessed words so that the player will be able to narrow down the possibilities of guessing the right word.

You may use any appropriate functions from the C++ libraries for this project. Among the suggested functions are srand(), and rand() to generate random numbers, characters, or words. Use the clear the screen function to display the new figures each time the player enters a wrong guess.

You may refer to examples of such games from any other sources such as the internet. Find out the use of C++ functions from external sources beside the main reference text. Remember to quote any references or codes taken from other sources.

I PREFER TO USE NUMBER AS THE GUESTING WORDS

ok, thanks. i will try to solve it myself first.

I didn't quite understand the problem. Is it a hangman game, or a number guessing game? If its hangman, then consider the following plan:
Create a vector of words
Create a vector of hints
Select a random word and how ever many hints you want from the vector
create a string of used letters
while guess doesn't equal the word && wrong < maxwrong
display word so far, display guessed words
ask for input
if guess is in string used
ask for input
if guess is in the word
congratulate player
else
increment wrong
Tell player sorry, no
display hint1

Hopefully this will help you get started. If you need help with any of the specific coding like vectors, please reply so.
If it is guess a number, then you can learn that from any online tutorial.
Generate random number, if guess > number: nope too high.
If guess < Nope too low. If guess = number you win.

actually it's a hangman game that guest a letter or a number. i prefer to make it to guest number because it easier to create the hint. anyway, thanks for your help.. :-)

i just learn c++ until function only. from that onward i'm not learn yet (array vector .etc)

*sorry for my bad english.

i have finally complete mu assignment.. yahooooo.. here's my source for those who need it.. remember, sharing is caring..

#include "stdafx.h"
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <conio.h>
#include "stdlib.h"


using namespace std;
int main()
{
system ("color 0a");
srand(time(0)); // seed random number generator

int theNumber = rand() % 10 + 1; //random number between 1 and 10
int tries = 0, guess, start = 0;

cout << "\n\n\n\n\n\n\n";
cout << "\t\t\t********************************\n";
cout << "\t\t\t* Welcome to HANGMAN GAME v1.0 *\n";
cout << "\t\t\t*                              *\n";
cout << "\t\t\t* Programmer:                  *\n";
cout << "\t\t\t* Muhamad Bin Abd Majid        *\n";
cout << "\t\t\t* 012008110384                 *\n";
cout << "\t\t\t********************************\n";
cout << "\n\n\n\t\t\tPress any key to continue...";
getch();
system ("cls");

cout << "\t\tINTRUCTION\n\n";
cout << "This game will ask to to guess a number.\n";
cout << "You have 5 trial, each fail try will be given a clue.\n";
cout << "After 5 times, GAME OVER.\n\n\n";
system ("pause");
system ("cls");

//Guessing Loop
do
{
tries++;
switch(tries)
{
case 1:
cout << "\n\n";
cout << "\t\t\t000000000000000000000"         << endl;
cout << "\t\t\t00                  0"         << endl;
cout << "\t\t\t00                  0"         << endl;
cout << "\t\t\t00                 "      << endl;
cout << "\t\t\t00                "     << endl;
cout << "\t\t\t00                 "      << endl;
cout << "\t\t\t00                   "        << endl;
cout << "\t\t\t00                   "      << endl;
cout << "\t\t\t00                 "     << endl;
cout << "\t\t\t00                  "        << endl;
cout << "\t\t\t00                  "        << endl;
cout << "\t\t\t00                   "      << endl;
cout << "\t\t\t00                  "     << endl;
cout << "\t\t\t00"                           << endl;
cout << "\t\t\t00"                           << endl;
cout << "\t\t\t000000000000000000000000000"  << endl;
cout << "\t\t\t000000000000000000000000000"   << endl;
break;

case 2:
cout << "\t\t\t000000000000000000000"         << endl;
cout << "\t\t\t00                  0"         << endl;
cout << "\t\t\t00                  0"         << endl;
cout << "\t\t\t00                .***."       << endl;
cout << "\t\t\t00               *     *"      << endl;
cout << "\t\t\t00                *****"       << endl;
cout << "\t\t\t00                  "          << endl;
cout << "\t\t\t00                  "          << endl;
cout << "\t\t\t00                 "           << endl;
cout << "\t\t\t00                  "          << endl;
cout << "\t\t\t00                  "          << endl;
cout << "\t\t\t00                  "          << endl;
cout << "\t\t\t00                 "           << endl;
cout << "\t\t\t00"                            << endl;
cout << "\t\t\t00"                            << endl;
cout << "\t\t\t000000000000000000000000000"   << endl;
cout << "\t\t\t000000000000000000000000000"   << endl;
break; 

case 3: 
cout << "\t\t\t000000000000000000000"        << endl;
cout << "\t\t\t00                  0"        << endl;
cout << "\t\t\t00                  0"        << endl;
cout << "\t\t\t00                .***."      << endl;
cout << "\t\t\t00               *     *"     << endl;
cout << "\t\t\t00                *****"      << endl;
cout << "\t\t\t00                  *"        << endl;
cout << "\t\t\t00                  * "       << endl;
cout << "\t\t\t00                  *  "      << endl;
cout << "\t\t\t00                  *"        << endl;
cout << "\t\t\t00                  *"        << endl;
cout << "\t\t\t00                  * "       << endl;
cout << "\t\t\t00                     "      << endl;
cout << "\t\t\t00"                           << endl;
cout << "\t\t\t00"                           << endl;
cout << "\t\t\t000000000000000000000000000"  << endl;
cout << "\t\t\t000000000000000000000000000"  << endl;
break;

case 4: 
cout << "\t\t\t000000000000000000000"         << endl;
cout << "\t\t\t00                  0"         << endl;
cout << "\t\t\t00                  0"         << endl;
cout << "\t\t\t00                .***."      << endl;
cout << "\t\t\t00               *     *"     << endl;
cout << "\t\t\t00                *****"      << endl;
cout << "\t\t\t00                  *"        << endl;
cout << "\t\t\t00                 /*\\ "      << endl;
cout << "\t\t\t00                / * \\ "     << endl;
cout << "\t\t\t00                  *"        << endl;
cout << "\t\t\t00                  *"        << endl;
cout << "\t\t\t00                  * "      << endl;
cout << "\t\t\t00                    "     << endl;
cout << "\t\t\t00"                           << endl;
cout << "\t\t\t00"                           << endl;
cout << "\t\t\t000000000000000000000000000"  << endl;
cout << "\t\t\t000000000000000000000000000"   << endl;
break; 

case 5:
cout << "\t\t\t000000000000000000000"         << endl;
cout << "\t\t\t00                  0"         << endl;
cout << "\t\t\t00                  0"         << endl;
cout << "\t\t\t00                .***."      << endl;
cout << "\t\t\t00               *     *"     << endl;
cout << "\t\t\t00                *****"      << endl;
cout << "\t\t\t00                  *"        << endl;
cout << "\t\t\t00                 /*\\ "      << endl;
cout << "\t\t\t00                / * \\ "     << endl;
cout << "\t\t\t00                  *"        << endl;
cout << "\t\t\t00                  *"        << endl;
cout << "\t\t\t00                  *\\ "      << endl;
cout << "\t\t\t00                    \\ "     << endl;
cout << "\t\t\t00"                           << endl;
cout << "\t\t\t00"                           << endl;
cout << "\t\t\t000000000000000000000000000"  << endl;
cout << "\t\t\t000000000000000000000000000"   << endl;
break; 

case 6:
cout << "\t\t\t000000000000000000000"         << endl;
cout << "\t\t\t00                  0"         << endl;
cout << "\t\t\t00                  0"         << endl;
cout << "\t\t\t00                .***."      << endl;
cout << "\t\t\t00               *     *"     << endl;
cout << "\t\t\t00                *****"      << endl;
cout << "\t\t\t00                  *"        << endl;
cout << "\t\t\t00                 /*\\ "      << endl;
cout << "\t\t\t00                / * \\ "     << endl;
cout << "\t\t\t00                  *"        << endl;
cout << "\t\t\t00                  *"        << endl;
cout << "\t\t\t00                 /*\\ "      << endl;
cout << "\t\t\t00                /   \\ "     << endl;
cout << "\t\t\t00"                           << endl;
cout << "\t\t\t00"                           << endl;
cout << "\t\t\t000000000000000000000000000"  << endl;
cout << "\t\t\t000000000000000000000000000"   << endl;
cout << "\n\n\n\n\t\t\tBETTER LUCK NEXT TIME" << endl;
break;
} 

if (tries!=6)
{cout << "\nEnter a guess: ";
cin  >> guess;
system ("cls");}
else
getch();

if (guess > theNumber)
cout << "Too high!\n\n";

if (guess < theNumber)
cout << "Too low!\n\n";

if (guess == theNumber)
{
cout << "\nThat's it! You got it in " << tries << " guesses!\n";
getch();
break;

}

++start;
} while (start < 6);

}

Congratulations.

But using code tags would have been a good idea, if you wanted people to read it.

TQ, you encourage me a lot. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.