I am implementing code to program a hangman game in C++ for my CSP class. So far, I am working on the random string function as well as calling the body parts as void functions. I am attempting to compile what I have as of now to see how it runs, but I run into a problem. I declared some variables in a function, so how do I use them and their values in the main portion of the program? The code and errors are posted here. I am trying to call the values of choice and hint as determined in the getString function in the main portion of the program.

// Kevin Richard
// Hangman.cpp
// Basic Hangman console game

/* 
Changelog:
-added char guess, and string lettersUsed.
-implemented help call.
-added void subfunctions for the body parts of the hanged man.
*/ 


#include "stdafx.h"
#include "iostream"
#include "string"
#include "cmath"
#include "ctime" 
#include "cstdlib"
#include "conio.h"

using namespace std;

void getString();
void head();
void headBody();
void headBodyLeftArm();
void headBodyRightArm();
void headBodyLeftLeg();
void dead();

int main()
{
	string guess;
	string lettersUsed;
	int triesLeft;
	int bodyCount;
	int position;

	getString();
	
	
	bodyCount=6;
	triesLeft=bodyCount;

	cout << "Welcome to Hangman! Guess the letters in the word to win." << endl;
	
	while(triesLeft != 0)
	{
		cout << "Enter a letter to guess or enter '!' for a hint." << endl;
		
		if (guess == "!")	//May need its "" or == changed.
		{
		cout << hint << endl;
		}
		else
		{
			position = choice.find(guess);
			if(position = false)
			{
				cout << "Incorrect guess!" << endl;
				lettersUsed = lettersUsed + guess;
				triesLeft = bodyCount - 1;
			}
			else
			{
				cout << "That letter is in the word!" << endl;
				triesLeft = bodyCount;
			}
		}
	}

	getchar();

	return 0;
}
void getString()
{
	string wordOne = "bases";
	string wordTwo = "catcher";
	string wordThree = "pitcher";
	string wordFour = "outfield";
	string wordFive = "infield";
	string wordSix = "bleachers";
	string wordSeven = "stadium";
	string wordEight = "peanuts";
	string wordNine = "batboy";
	string wordTen = "crowd";
	string choice;
	string lettersUsed;
	string hint;
	
	cout << "*************************" << endl;
	cout << "*        Hangman        *" << endl;
	cout << "*          v.1          *" << endl;
	cout << "*************************" << endl;
	cout << "                         " << endl;
	
	/* 
	Random number generator code found at: http://www.daniweb.com/forums/thread1769.html
	Posted by: Bob
	Daniweb IT Discussion Community Forums
	Thread: C++ Random Numbers
	*/

	srand((unsigned)time(0)); 
	int random_integer; 
	int lowest=1, highest=10; 
	int range=(highest-lowest)+1; 
	for(int index=0; index<2; index++)
	{ 
		random_integer = lowest+int(range*rand()/(RAND_MAX + 1.0));
	}
	/*
	End of C++ Random Number code as found on http://www.daniweb.com/forums/thread1769.html
	*/

	if(random_integer == 1)
	{
		choice = wordOne;
		hint = "A sucessful batter will run the _____.";
	}
	else if(random_integer == 2)
	{
		choice = wordTwo;
		hint = "If the batter missed, the _____ gets the ball.";
	}
	else if(random_integer == 3)
	{
		choice = wordThree;
		hint = "Throws the ball at the batter.";
	}
	else if(random_integer == 4)
	{
		choice = wordFour;
		hint = "Further away than the outfield.";
	}
	else if(random_integer == 5)
	{
		choice = wordFive;
		hint = "Closer than the outfield.";
	}
	else if(random_integer == 6)
	{
		choice = wordSix;
		hint = "The worst seats in the house.";
	}
	else if(random_integer == 7)
	{
		choice = wordSeven;
		hint = "Shea or Madison Square Garden are examples of one of these.";
	}
	else if(random_integer == 8)
	{
		choice = wordEight;
		hint = "Buy me some _____ and Cracker Jacks...";
	}
	else if(random_integer == 9)
	{
		choice = wordNine;
		hint = "Runs after the bats when the batter throws them.";
	}
	else if(random_integer == 10)
	{
		choice = wordTen;
		hint = "For the world series, the stadium always has a big _____.";
	}
	else if(random_integer > 10)
	{
		choice = wordFive;
		hint = "Closer than the outfield.";
	}

}

void head()
{
	cout << "       * *       " << endl;
	cout << "     *     *     " << endl;
	cout << "    *  x x  *    " << endl;
	cout << "    *       *    " << endl;
	cout << "     *     *     " << endl;
	cout << "       * *       " << endl;
}

void headBody()
{
	cout << "       * *       " << endl;
	cout << "     *     *     " << endl;
	cout << "    *  x x  *    " << endl;
	cout << "    *       *    " << endl;
	cout << "     *     *     " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
}

void headBodyLeftArm()
{
	cout << "       * *       " << endl;
	cout << "     *     *     " << endl;
	cout << "    *  x x  *    " << endl;
	cout << "    *       *    " << endl;
	cout << "*    *     *     " << endl;
	cout << " *     * *       " << endl;
	cout << "   *   * *       " << endl;
	cout << "     * * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
}

void headBodyRightArm()
{
	cout << "       * *       " << endl;
	cout << "     *     *     " << endl;
	cout << "    *  x x  *    " << endl;
	cout << "    *       *    " << endl;
	cout << "*    *     *    *" << endl;
	cout << " *     * *     * " << endl;
	cout << "   *   * *   *   " << endl;
	cout << "     * * * *     " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
}

void headBodyLeftLeg()
{
	cout << "       * *       " << endl;
	cout << "     *     *     " << endl;
	cout << "    *  x x  *    " << endl;
	cout << "    *       *    " << endl;
	cout << "*    *     *    *" << endl;
	cout << " *     * *     * " << endl;
	cout << "   *   * *   *   " << endl;
	cout << "     * * * *     " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "      *          " << endl;
	cout << "     *           " << endl;
	cout << "    *            " << endl;
	cout << "   *             " << endl;
	cout << "  *              " << endl;
	cout << " *               " << endl;
	cout << "*                " << endl;
}

void dead()
{
	cout << "       * *       " << endl;
	cout << "     *     *     " << endl;
	cout << "    *  x x  *    " << endl;
	cout << "    *       *    " << endl;
	cout << "*    *     *    *" << endl;
	cout << " *     * *     * " << endl;
	cout << "   *   * *   *   " << endl;
	cout << "     * * * *     " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "      *   *      " << endl;
	cout << "     *     *     " << endl;
	cout << "    *       *    " << endl;
	cout << "   *         *   " << endl;
	cout << "  *           *  " << endl;
	cout << " *             * " << endl;
	cout << "*               *" << endl;
}

The output I get when compiling is

1>------ Build started: Project: Hangman, Configuration: Debug Win32 ------
1>Compiling...
1>Hangman.cpp
1>c:\documents and settings\black_hatter\my documents\visual studio 2008\projects\hangman\hangman\hangman.cpp(53) : error C2065: 'hint' : undeclared identifier
1>c:\documents and settings\black_hatter\my documents\visual studio 2008\projects\hangman\hangman\hangman.cpp(57) : error C2065: 'choice' : undeclared identifier
1>c:\documents and settings\black_hatter\my documents\visual studio 2008\projects\hangman\hangman\hangman.cpp(57) : error C2228: left of '.find' must have class/struct/union
1>        type is ''unknown-type''
1>Build log was saved at "file://c:\Documents and Settings\black_hatter\My Documents\Visual Studio 2008\Projects\Hangman\Hangman\Debug\BuildLog.htm"
1>Hangman - 3 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

You will want to declare those two variables in your main function. Then call your GetString() function with two arguments by reference. As in saying change the declaration of GetString to GetString(string &choice, string &hint); This will send the pointers to the function allowing them to manipulate the values directly and returning them to you without any problems what so ever.

Cameron

Edit: Also I would check out when you say how many times they have tried. From what I can tell, they will just be able to keep going because BodyCount never truly decreases try BodyCount-- instead.

That's a very good solution. If your teacher has not gone over pass-by-value vs. pass-by-reference, or global vs. local variables, now would be a good time to bring that up.

CAMERON, FOR THE WIN!!!

commented: A compliment always makes my day better, Thanks! +1

You will want to declare those two variables in your main function. Then call your GetString() function with two arguments by reference. As in saying change the declaration of GetString to GetString(string &choice, string &hint); This will send the pointers to the function allowing them to manipulate the values directly and returning them to you without any problems what so ever.

Cameron

Edit: Also I would check out when you say how many times they have tried. From what I can tell, they will just be able to keep going because BodyCount never truly decreases try BodyCount-- instead.

Now using that code, when I compile, I get these errors:

1>------ Build started: Project: Hangman, Configuration: Debug Win32 ------
1>Compiling...
1>Hangman.cpp
1>c:\documents and settings\black_hatter\my documents\visual studio 2008\projects\hangman\hangman\hangman.cpp(41) : error C2275: 'std::string' : illegal use of this type as an expression
1>        c:\program files\microsoft visual studio 9.0\vc\include\xstring(2210) : see declaration of 'std::string'
1>c:\documents and settings\black_hatter\my documents\visual studio 2008\projects\hangman\hangman\hangman.cpp(41) : error C2275: 'std::string' : illegal use of this type as an expression
1>        c:\program files\microsoft visual studio 9.0\vc\include\xstring(2210) : see declaration of 'std::string'
1>c:\documents and settings\black_hatter\my documents\visual studio 2008\projects\hangman\hangman\hangman.cpp(90) : error C2082: redefinition of formal parameter 'choice'
1>c:\documents and settings\black_hatter\my documents\visual studio 2008\projects\hangman\hangman\hangman.cpp(92) : error C2082: redefinition of formal parameter 'hint'
1>Build log was saved at "file://c:\Documents and Settings\black_hatter\My Documents\Visual Studio 2008\Projects\Hangman\Hangman\Debug\BuildLog.htm"
1>Hangman - 4 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Paste your new code so I can compare where/what went on, thank you.

Cameron

// Kevin Richard
// Hangman.cpp
// Basic Hangman console game

/* 
Changelog:
-added char guess, and string lettersUsed.
-implemented help call.
-added void subfunctions for the body parts of the hanged man.
*/ 


#include "stdafx.h"
#include "iostream"
#include "string"
#include "cmath"
#include "ctime" 
#include "cstdlib"
#include "conio.h"

using namespace std;

void getString(string, string);
void head();
void headBody();
void headBodyLeftArm();
void headBodyRightArm();
void headBodyLeftLeg();
void dead();

int main()
{
	string guess;
	string lettersUsed;
	string choice;
	string hint;
	int triesLeft;
	int bodyCount;
	int position;

	getString(string &choice, string &hint);
	
	
	bodyCount=6;
	triesLeft=bodyCount;

	cout << "Welcome to Hangman! Guess the letters in the word to win." << endl;
	
	while(triesLeft != 0)
	{
		cout << "Enter a letter to guess or enter '!' for a hint." << endl;
		
		if (guess == "!")	//May need its "" or == changed.
		{
		cout << hint << endl;
		}
		else
		{
			position = choice.find(guess);
			if(position = false)
			{
				cout << "Incorrect guess!" << endl;
				lettersUsed = lettersUsed + guess;
				triesLeft = bodyCount--;
			}
			else
			{
				cout << "That letter is in the word!" << endl;
				triesLeft = bodyCount;
			}
		}
	}

	getchar();

	return 0;
}
void getString(string choice, string hint)
{
	string wordOne = "bases";
	string wordTwo = "catcher";
	string wordThree = "pitcher";
	string wordFour = "outfield";
	string wordFive = "infield";
	string wordSix = "bleachers";
	string wordSeven = "stadium";
	string wordEight = "peanuts";
	string wordNine = "batboy";
	string wordTen = "crowd";
	string choice;
	string lettersUsed;
	string hint;
	
	cout << "*************************" << endl;
	cout << "*        Hangman        *" << endl;
	cout << "*          v.1          *" << endl;
	cout << "*************************" << endl;
	cout << "                         " << endl;
	
	/* 
	Random number generator code found at: http://www.daniweb.com/forums/thread1769.html
	Posted by: Bob
	Daniweb IT Discussion Community Forums
	Thread: C++ Random Numbers
	*/

	srand((unsigned)time(0)); 
	int random_integer; 
	int lowest=1, highest=10; 
	int range=(highest-lowest)+1; 
	for(int index=0; index<2; index++)
	{ 
		random_integer = lowest+int(range*rand()/(RAND_MAX + 1.0));
	}
	/*
	End of C++ Random Number code as found on http://www.daniweb.com/forums/thread1769.html
	*/

	if(random_integer == 1)
	{
		choice = wordOne;
		hint = "A sucessful batter will run the _____.";
	}
	else if(random_integer == 2)
	{
		choice = wordTwo;
		hint = "If the batter missed, the _____ gets the ball.";
	}
	else if(random_integer == 3)
	{
		choice = wordThree;
		hint = "Throws the ball at the batter.";
	}
	else if(random_integer == 4)
	{
		choice = wordFour;
		hint = "Further away than the outfield.";
	}
	else if(random_integer == 5)
	{
		choice = wordFive;
		hint = "Closer than the outfield.";
	}
	else if(random_integer == 6)
	{
		choice = wordSix;
		hint = "The worst seats in the house.";
	}
	else if(random_integer == 7)
	{
		choice = wordSeven;
		hint = "Shea or Madison Square Garden are examples of one of these.";
	}
	else if(random_integer == 8)
	{
		choice = wordEight;
		hint = "Buy me some _____ and Cracker Jacks...";
	}
	else if(random_integer == 9)
	{
		choice = wordNine;
		hint = "Runs after the bats when the batter throws them.";
	}
	else if(random_integer == 10)
	{
		choice = wordTen;
		hint = "For the world series, the stadium always has a big _____.";
	}
	else if(random_integer > 10)
	{
		choice = wordFive;
		hint = "Closer than the outfield.";
	}

}

void head()
{
	cout << "       * *       " << endl;
	cout << "     *     *     " << endl;
	cout << "    *  x x  *    " << endl;
	cout << "    *       *    " << endl;
	cout << "     *     *     " << endl;
	cout << "       * *       " << endl;
}

void headBody()
{
	cout << "       * *       " << endl;
	cout << "     *     *     " << endl;
	cout << "    *  x x  *    " << endl;
	cout << "    *       *    " << endl;
	cout << "     *     *     " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
}

void headBodyLeftArm()
{
	cout << "       * *       " << endl;
	cout << "     *     *     " << endl;
	cout << "    *  x x  *    " << endl;
	cout << "    *       *    " << endl;
	cout << "*    *     *     " << endl;
	cout << " *     * *       " << endl;
	cout << "   *   * *       " << endl;
	cout << "     * * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
}

void headBodyRightArm()
{
	cout << "       * *       " << endl;
	cout << "     *     *     " << endl;
	cout << "    *  x x  *    " << endl;
	cout << "    *       *    " << endl;
	cout << "*    *     *    *" << endl;
	cout << " *     * *     * " << endl;
	cout << "   *   * *   *   " << endl;
	cout << "     * * * *     " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
}

void headBodyLeftLeg()
{
	cout << "       * *       " << endl;
	cout << "     *     *     " << endl;
	cout << "    *  x x  *    " << endl;
	cout << "    *       *    " << endl;
	cout << "*    *     *    *" << endl;
	cout << " *     * *     * " << endl;
	cout << "   *   * *   *   " << endl;
	cout << "     * * * *     " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "      *          " << endl;
	cout << "     *           " << endl;
	cout << "    *            " << endl;
	cout << "   *             " << endl;
	cout << "  *              " << endl;
	cout << " *               " << endl;
	cout << "*                " << endl;
}

void dead()
{
	cout << "       * *       " << endl;
	cout << "     *     *     " << endl;
	cout << "    *  x x  *    " << endl;
	cout << "    *       *    " << endl;
	cout << "*    *     *    *" << endl;
	cout << " *     * *     * " << endl;
	cout << "   *   * *   *   " << endl;
	cout << "     * * * *     " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "      *   *      " << endl;
	cout << "     *     *     " << endl;
	cout << "    *       *    " << endl;
	cout << "   *         *   " << endl;
	cout << "  *           *  " << endl;
	cout << " *             * " << endl;
	cout << "*               *" << endl;
}

please post it with (code = cplusplus) (/code) wrapped around the code please. it will help with identifying the line numbers that the errors are occuring at. (replace the round brackets with these [ ] )

// Kevin Richard
// Hangman.cpp
// Basic Hangman console game

/* 
Changelog:
-added char guess, and string lettersUsed.
-implemented help call.
-added void subfunctions for the body parts of the hanged man.
*/ 


#include "stdafx.h"
#include "iostream"
#include "string"
#include "cmath"
#include "ctime" 
#include "cstdlib"
#include "conio.h"

using namespace std;

void getString(string, string);
void head();
void headBody();
void headBodyLeftArm();
void headBodyRightArm();
void headBodyLeftLeg();
void dead();

int main()
{
	string guess;
	string lettersUsed;
	string choice;
	string hint;
	int triesLeft;
	int bodyCount;
	int position;

	getString(string &choice, string &hint);
	
	
	bodyCount=6;
	triesLeft=bodyCount;

	cout << "Welcome to Hangman! Guess the letters in the word to win." << endl;
	
	while(triesLeft != 0)
	{
		cout << "Enter a letter to guess or enter '!' for a hint." << endl;
		
		if (guess == "!")	//May need its "" or == changed.
		{
		cout << hint << endl;
		}
		else
		{
			position = choice.find(guess);
			if(position = false)
			{
				cout << "Incorrect guess!" << endl;
				lettersUsed = lettersUsed + guess;
				triesLeft = bodyCount--;
			}
			else
			{
				cout << "That letter is in the word!" << endl;
				triesLeft = bodyCount;
			}
		}
	}

	getchar();

	return 0;
}
void getString(string choice, string hint)
{
	string wordOne = "bases";
	string wordTwo = "catcher";
	string wordThree = "pitcher";
	string wordFour = "outfield";
	string wordFive = "infield";
	string wordSix = "bleachers";
	string wordSeven = "stadium";
	string wordEight = "peanuts";
	string wordNine = "batboy";
	string wordTen = "crowd";
	string choice;
	string lettersUsed;
	string hint;
	
	cout << "*************************" << endl;
	cout << "*        Hangman        *" << endl;
	cout << "*          v.1          *" << endl;
	cout << "*************************" << endl;
	cout << "                         " << endl;
	
	/* 
	Random number generator code found at: http://www.daniweb.com/forums/thread1769.html
	Posted by: Bob
	Daniweb IT Discussion Community Forums
	Thread: C++ Random Numbers
	*/

	srand((unsigned)time(0)); 
	int random_integer; 
	int lowest=1, highest=10; 
	int range=(highest-lowest)+1; 
	for(int index=0; index<2; index++)
	{ 
		random_integer = lowest+int(range*rand()/(RAND_MAX + 1.0));
	}
	/*
	End of C++ Random Number code as found on http://www.daniweb.com/forums/thread1769.html
	*/

	if(random_integer == 1)
	{
		choice = wordOne;
		hint = "A sucessful batter will run the _____.";
	}
	else if(random_integer == 2)
	{
		choice = wordTwo;
		hint = "If the batter missed, the _____ gets the ball.";
	}
	else if(random_integer == 3)
	{
		choice = wordThree;
		hint = "Throws the ball at the batter.";
	}
	else if(random_integer == 4)
	{
		choice = wordFour;
		hint = "Further away than the outfield.";
	}
	else if(random_integer == 5)
	{
		choice = wordFive;
		hint = "Closer than the outfield.";
	}
	else if(random_integer == 6)
	{
		choice = wordSix;
		hint = "The worst seats in the house.";
	}
	else if(random_integer == 7)
	{
		choice = wordSeven;
		hint = "Shea or Madison Square Garden are examples of one of these.";
	}
	else if(random_integer == 8)
	{
		choice = wordEight;
		hint = "Buy me some _____ and Cracker Jacks...";
	}
	else if(random_integer == 9)
	{
		choice = wordNine;
		hint = "Runs after the bats when the batter throws them.";
	}
	else if(random_integer == 10)
	{
		choice = wordTen;
		hint = "For the world series, the stadium always has a big _____.";
	}
	else if(random_integer > 10)
	{
		choice = wordFive;
		hint = "Closer than the outfield.";
	}

}

void head()
{
	cout << "       * *       " << endl;
	cout << "     *     *     " << endl;
	cout << "    *  x x  *    " << endl;
	cout << "    *       *    " << endl;
	cout << "     *     *     " << endl;
	cout << "       * *       " << endl;
}

void headBody()
{
	cout << "       * *       " << endl;
	cout << "     *     *     " << endl;
	cout << "    *  x x  *    " << endl;
	cout << "    *       *    " << endl;
	cout << "     *     *     " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
}

void headBodyLeftArm()
{
	cout << "       * *       " << endl;
	cout << "     *     *     " << endl;
	cout << "    *  x x  *    " << endl;
	cout << "    *       *    " << endl;
	cout << "*    *     *     " << endl;
	cout << " *     * *       " << endl;
	cout << "   *   * *       " << endl;
	cout << "     * * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
}

void headBodyRightArm()
{
	cout << "       * *       " << endl;
	cout << "     *     *     " << endl;
	cout << "    *  x x  *    " << endl;
	cout << "    *       *    " << endl;
	cout << "*    *     *    *" << endl;
	cout << " *     * *     * " << endl;
	cout << "   *   * *   *   " << endl;
	cout << "     * * * *     " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
}

void headBodyLeftLeg()
{
	cout << "       * *       " << endl;
	cout << "     *     *     " << endl;
	cout << "    *  x x  *    " << endl;
	cout << "    *       *    " << endl;
	cout << "*    *     *    *" << endl;
	cout << " *     * *     * " << endl;
	cout << "   *   * *   *   " << endl;
	cout << "     * * * *     " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "      *          " << endl;
	cout << "     *           " << endl;
	cout << "    *            " << endl;
	cout << "   *             " << endl;
	cout << "  *              " << endl;
	cout << " *               " << endl;
	cout << "*                " << endl;
}

void dead()
{
	cout << "       * *       " << endl;
	cout << "     *     *     " << endl;
	cout << "    *  x x  *    " << endl;
	cout << "    *       *    " << endl;
	cout << "*    *     *    *" << endl;
	cout << " *     * *     * " << endl;
	cout << "   *   * *   *   " << endl;
	cout << "     * * * *     " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "      *   *      " << endl;
	cout << "     *     *     " << endl;
	cout << "    *       *    " << endl;
	cout << "   *         *   " << endl;
	cout << "  *           *  " << endl;
	cout << " *             * " << endl;
	cout << "*               *" << endl;
}

hmmm maybe try making that code=c++ instead...that didnt seem to wrap properly

// Kevin Richard
// Hangman.cpp
// Basic Hangman console game

/* 
Changelog:
-added char guess, and string lettersUsed.
-implemented help call.
-added void subfunctions for the body parts of the hanged man.
*/ 


#include "stdafx.h"
#include "iostream"
#include "string"
#include "cmath"
#include "ctime" 
#include "cstdlib"
#include "conio.h"

using namespace std;

void getString(string, string);
void head();
void headBody();
void headBodyLeftArm();
void headBodyRightArm();
void headBodyLeftLeg();
void dead();

int main()
{
	string guess;
	string lettersUsed;
	string choice;
	string hint;
	int triesLeft;
	int bodyCount;
	int position;

	getString(string &choice, string &hint);
	
	
	bodyCount=6;
	triesLeft=bodyCount;

	cout << "Welcome to Hangman! Guess the letters in the word to win." << endl;
	
	while(triesLeft != 0)
	{
		cout << "Enter a letter to guess or enter '!' for a hint." << endl;
		
		if (guess == "!")	//May need its "" or == changed.
		{
		cout << hint << endl;
		}
		else
		{
			position = choice.find(guess);
			if(position = false)
			{
				cout << "Incorrect guess!" << endl;
				lettersUsed = lettersUsed + guess;
				triesLeft = bodyCount--;
			}
			else
			{
				cout << "That letter is in the word!" << endl;
				triesLeft = bodyCount;
			}
		}
	}

	getchar();

	return 0;
}
void getString(string choice, string hint)
{
	string wordOne = "bases";
	string wordTwo = "catcher";
	string wordThree = "pitcher";
	string wordFour = "outfield";
	string wordFive = "infield";
	string wordSix = "bleachers";
	string wordSeven = "stadium";
	string wordEight = "peanuts";
	string wordNine = "batboy";
	string wordTen = "crowd";
	string choice;
	string lettersUsed;
	string hint;
	
	cout << "*************************" << endl;
	cout << "*        Hangman        *" << endl;
	cout << "*          v.1          *" << endl;
	cout << "*************************" << endl;
	cout << "                         " << endl;
	
	/* 
	Random number generator code found at: http://www.daniweb.com/forums/thread1769.html
	Posted by: Bob
	Daniweb IT Discussion Community Forums
	Thread: C++ Random Numbers
	*/

	srand((unsigned)time(0)); 
	int random_integer; 
	int lowest=1, highest=10; 
	int range=(highest-lowest)+1; 
	for(int index=0; index<2; index++)
	{ 
		random_integer = lowest+int(range*rand()/(RAND_MAX + 1.0));
	}
	/*
	End of C++ Random Number code as found on http://www.daniweb.com/forums/thread1769.html
	*/

	if(random_integer == 1)
	{
		choice = wordOne;
		hint = "A sucessful batter will run the _____.";
	}
	else if(random_integer == 2)
	{
		choice = wordTwo;
		hint = "If the batter missed, the _____ gets the ball.";
	}
	else if(random_integer == 3)
	{
		choice = wordThree;
		hint = "Throws the ball at the batter.";
	}
	else if(random_integer == 4)
	{
		choice = wordFour;
		hint = "Further away than the outfield.";
	}
	else if(random_integer == 5)
	{
		choice = wordFive;
		hint = "Closer than the outfield.";
	}
	else if(random_integer == 6)
	{
		choice = wordSix;
		hint = "The worst seats in the house.";
	}
	else if(random_integer == 7)
	{
		choice = wordSeven;
		hint = "Shea or Madison Square Garden are examples of one of these.";
	}
	else if(random_integer == 8)
	{
		choice = wordEight;
		hint = "Buy me some _____ and Cracker Jacks...";
	}
	else if(random_integer == 9)
	{
		choice = wordNine;
		hint = "Runs after the bats when the batter throws them.";
	}
	else if(random_integer == 10)
	{
		choice = wordTen;
		hint = "For the world series, the stadium always has a big _____.";
	}
	else if(random_integer > 10)
	{
		choice = wordFive;
		hint = "Closer than the outfield.";
	}

}

void head()
{
	cout << "       * *       " << endl;
	cout << "     *     *     " << endl;
	cout << "    *  x x  *    " << endl;
	cout << "    *       *    " << endl;
	cout << "     *     *     " << endl;
	cout << "       * *       " << endl;
}

void headBody()
{
	cout << "       * *       " << endl;
	cout << "     *     *     " << endl;
	cout << "    *  x x  *    " << endl;
	cout << "    *       *    " << endl;
	cout << "     *     *     " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
}

void headBodyLeftArm()
{
	cout << "       * *       " << endl;
	cout << "     *     *     " << endl;
	cout << "    *  x x  *    " << endl;
	cout << "    *       *    " << endl;
	cout << "*    *     *     " << endl;
	cout << " *     * *       " << endl;
	cout << "   *   * *       " << endl;
	cout << "     * * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
}

void headBodyRightArm()
{
	cout << "       * *       " << endl;
	cout << "     *     *     " << endl;
	cout << "    *  x x  *    " << endl;
	cout << "    *       *    " << endl;
	cout << "*    *     *    *" << endl;
	cout << " *     * *     * " << endl;
	cout << "   *   * *   *   " << endl;
	cout << "     * * * *     " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
}

void headBodyLeftLeg()
{
	cout << "       * *       " << endl;
	cout << "     *     *     " << endl;
	cout << "    *  x x  *    " << endl;
	cout << "    *       *    " << endl;
	cout << "*    *     *    *" << endl;
	cout << " *     * *     * " << endl;
	cout << "   *   * *   *   " << endl;
	cout << "     * * * *     " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "      *          " << endl;
	cout << "     *           " << endl;
	cout << "    *            " << endl;
	cout << "   *             " << endl;
	cout << "  *              " << endl;
	cout << " *               " << endl;
	cout << "*                " << endl;
}

void dead()
{
	cout << "       * *       " << endl;
	cout << "     *     *     " << endl;
	cout << "    *  x x  *    " << endl;
	cout << "    *       *    " << endl;
	cout << "*    *     *    *" << endl;
	cout << " *     * *     * " << endl;
	cout << "   *   * *   *   " << endl;
	cout << "     * * * *     " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "       * *       " << endl;
	cout << "      *   *      " << endl;
	cout << "     *     *     " << endl;
	cout << "    *       *    " << endl;
	cout << "   *         *   " << endl;
	cout << "  *           *  " << endl;
	cout << " *             * " << endl;
	cout << "*               *" << endl;
}

line 23 - should be:
void getString(string &, string &);

line 41 - should be:
getString(choice, hint);

line 71 - should be:
void getString(string &choice, string &hint)

get rid of lines 90 and 92

Also, in all of the void functions with the ASCII graphics in them (the one's that draw the hangman) should have a return; line at the end. It looks like there's a few other bugs to be resolved, but I had no chance to compile it. Let me know if your still having troubles.

Some more bugs resolved:

Take out these #include lines:
#include "cstdlib.h"
#include "conio.h"
#include "cmath.h"
#include "stdafx.h"
as they arent neccessary and will only slow down the link time.

You need to have some sort of input in the GetString function, or it will just loop over and over again I'm pretty sure.

I think that should be all of the bugs for now!

ok now it compiles but i get an infinite loop after the user inputs the first letter guess...off to figure out why! thanks for all your help

No problem...And good luck!
Oh...I can help you with that too :P
Use this after every cin or getline entry:

cin.ignore(cin.rdbuf()->in_avail());

This will flush the keyboard input buffer, so that the return key isn't continually read as being input.

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.