Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,582 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,932 people online right now. Registration is fast and FREE... Join Now!




Hangman problem

 
Reply to this topicStart new topic

Hangman problem

villalandron
28 Sep, 2008 - 05:24 AM
Post #1

New D.I.C Head
*

Joined: 24 Sep, 2008
Posts: 23

Hello! I am trying to make a hangman game. I thought I had everything done the right way but I have some error messages and I don't understand how to correct them. Here is what I have:

This is how my code looks like:

cppview plainprint?
#include <iostream>
#include <fstream>
using namespace std;

#define MAX_WORD_SIZE 6
#define MAX_WORDS 255

void RunGame();
void DrawGallows(int State);

typedef char String[MAX_WORD_SIZE];
String Words[MAX_WORDS -1];
char choice, Yes;
char Continue = Yes;
int State;
int count;

int main()
{


cout << "Welcome to Hangman" << endl;

{
void RunGame();
cout << "Do you want to play again (Yes or No)?" << endl;
cin >> Continue;
Continue = toupper(Continue);
}

cout << "Thanks for Playing." << endl;

char C;
ifstream Datfile;

count=0;

while((C=Datfile.peek()) != EOF)

Datfile >> Words [count++];

if (count > MAX_WORDS - 1)

count--;
Datfile.close();

void Rungame();
{
int Word;
int Size;
int State = 1;
int Subscript=0;
char guess[MAX_WORD_SIZE];
char copy[MAX_WORD_SIZE];
char letter;
int Correct = 0;

strcpy_s(copy,Words[Word]);
Size = strlen(Words[Word]);
for(; Subscript < Size; Subscript++);
{
guess[Subscript] = '-';
}

guess[Subscript] = '\0';

while(State != 6)
{
DrawGallows(State);

cout << "Guess the word: XXXXXX" << endl;

cout << "Guess a letter: " << endl;
cin >> letter;

letter = tolower(letter);

for(Subscript =0; Subscript < Size; Subscript++)
{
if(copy[Subscript] == letter)

{
guess[Subscript] = letter;
Correct = 1;
cout << "Good Guess." << endl;

if(strcmp(Words[Word], guess) == 0)

{
cout << "Congratulations! You guessed the word...play again? Yes/No" << endl;
cin >> choice;
while(Continue == 'Yes');

}
}
}
if(Correct = 0)

{
cout << "Sorry, Bad Guess!" << endl;
State++;
}

Correct = 0;
}

DrawGallows(State);


}

void DrawGallows(int State);

{
if(State==6)

{
cout << endl << endl
<<" +----+ "<< endl
<<" | | "<< endl
<<" | O "<< endl
<<" | /|\ "<< endl
<<" | / \ "<< endl
<<" |Your Dead "<< endl
<<" ============"<< endl << endl;

}
else if(State==5)
{
cout<<endl<<endl
<<" +----+ "<<endl
<<" | | "<<endl
<<" | O "<<endl
<<" | /|\ "<<endl
<<" | \ "<<endl
<<" | "<<endl
<<" ============"<<endl<<endl;
}
else if(State==4)
{
cout<<endl<<endl
<<" +----+ "<<endl
<<" | | "<<endl
<<" | O "<<endl
<<" | /|\ "<<endl
<<" | "<<endl
<<" | "<<endl
<<" ============="<<endl<<endl;
}
else if(State==3)
{
cout<<endl<<endl
<<" +----+ "<<endl
<<" | | "<<endl
<<" | O "<<endl
<<" | /| "<<endl
<<" | "<<endl
<<" | "<<endl
<<" ============="<<endl<<endl;
}
else if(State==2)
{
cout<<endl<<endl
<<" +----+ "<<endl
<<" | | "<<endl
<<" | O "<<endl
<<" | | "<<endl
<<" | "<<endl
<<" | "<<endl
<<" ============="<<endl<<endl;
}
else if(State==1)
{
cout<<endl<<endl
<<" +----+ "<<endl
<<" | | "<<endl
<<" | "<<endl
<<" | "<<endl
<<" | "<<endl
<<" | "<<endl
<<" ============="<<endl<<endl;
}
}
system ("pause");
return 0;
}
#include <iostream>#include <fstream> using namespace std;#define MAX_WORD_SIZE 6#define MAX_WORDS 255 void RunGame(); void DrawGallows(int State); typedef char String[MAX_WORD_SIZE]; String Words[MAX_WORDS -1]; char choice, Yes; char Continue = Yes; int State; int count;int main(){ cout << "Welcome to Hangman" << endl; { void RunGame(); cout << "Do you want to play again (Yes or No)?" << endl; cin >> Continue; Continue = toupper(Continue); } cout << "Thanks for Playing." << endl; char C; ifstream Datfile; count=0; while((C=Datfile.peek()) != EOF) Datfile >> Words [count++]; if (count > MAX_WORDS - 1) count--; Datfile.close(); void Rungame(); { int Word; int Size; int State = 1; int Subscript=0; char guess[MAX_WORD_SIZE]; char copy[MAX_WORD_SIZE]; char letter; int Correct = 0; strcpy_s(copy,Words[Word]); Size = strlen(Words[Word]); for(; Subscript < Size; Subscript++); { guess[Subscript] = '-'; } guess[Subscript] = '\0'; while(State != 6) { DrawGallows(State); cout << "Guess the word: XXXXXX" << endl; cout << "Guess a letter: " << endl; cin >> letter; letter = tolower(letter); for(Subscript =0; Subscript < Size; Subscript++) { if(copy[Subscript] == letter) { guess[Subscript] = letter; Correct = 1; cout << "Good Guess." << endl; if(strcmp(Words[Word], guess) == 0) { cout << "Congratulations! You guessed the word...play again? Yes/No" << endl; cin >> choice; while(Continue == 'Yes'); } } } if(Correct = 0) { cout << "Sorry, Bad Guess!" << endl; State++; } Correct = 0; } DrawGallows(State); } void DrawGallows(int State); { if(State==6) { cout << endl << endl <<" +----+ "<< endl <<" | | "<< endl <<" | O "<< endl <<" | /|\ "<< endl <<" | / \ "<< endl <<" |Your Dead "<< endl <<" ============"<< endl << endl; } else if(State==5) { cout<<endl<<endl <<" +----+ "<<endl <<" | | "<<endl <<" | O "<<endl <<" | /|\ "<<endl <<" | \ "<<endl <<" | "<<endl <<" ============"<<endl<<endl; } else if(State==4) { cout<<endl<<endl <<" +----+ "<<endl <<" | | "<<endl <<" | O "<<endl <<" | /|\ "<<endl <<" | "<<endl <<" | "<<endl <<" ============="<<endl<<endl; } else if(State==3) { cout<<endl<<endl <<" +----+ "<<endl <<" | | "<<endl <<" | O "<<endl <<" | /| "<<endl <<" | "<<endl <<" | "<<endl <<" ============="<<endl<<endl; } else if(State==2) { cout<<endl<<endl <<" +----+ "<<endl <<" | | "<<endl <<" | O "<<endl <<" | | "<<endl <<" | "<<endl <<" | "<<endl <<" ============="<<endl<<endl; } else if(State==1) { cout<<endl<<endl <<" +----+ "<<endl <<" | | "<<endl <<" | "<<endl <<" | "<<endl <<" | "<<endl <<" | "<<endl <<" ============="<<endl<<endl; } } system ("pause");return 0;}


and these are the error messages:

1>.\hangman.cpp(128) : warning C4129: ' ' : unrecognized character escape sequence
1>.\hangman.cpp(129) : warning C4129: ' ' : unrecognized character escape sequence
1>.\hangman.cpp(140) : warning C4129: ' ' : unrecognized character escape sequence
1>.\hangman.cpp(141) : warning C4129: ' ' : unrecognized character escape sequence
1>.\hangman.cpp(151) : warning C4129: ' ' : unrecognized character escape sequence
1>c:\users\julio\documents\visual studio 2008\projects\hangman\hangman\hangman.cpp(64) : warning C4700: uninitialized local variable 'Word' used
1>Linking...
1>LINK : warning LNK4098: defaultlib 'MSVCRTD' conflicts with use of other libs; use /NODEFAULTLIB:library
1>hangman.obj : error LNK2028: unresolved token (0A000315) "void __cdecl DrawGallows(int)" (?DrawGallows@@$$FYAXH@Z) referenced in function "int __cdecl main(void)" (?main@@$$HYAHXZ)
1>hangman.obj : error LNK2019: unresolved external symbol "void __cdecl DrawGallows(int)" (?DrawGallows@@$$FYAXH@Z) referenced in function "int __cdecl main(void)" (?main@@$$HYAHXZ)
1>C:\Users\Julio\Documents\Visual Studio 2008\Projects\hangman\Debug\hangman.exe : fatal error LNK1120: 2 unresolved externals
1>Build log was saved at "file://c:\Users\Julio\Documents\Visual Studio 2008\Projects\hangman\hangman\Debug\BuildLog.htm"
1>hangman - 3 error(s), 7 warning(s)

Thank You for your help!
User is offlineProfile CardPM
+Quote Post

Psionics
RE: Hangman Problem
28 Sep, 2008 - 06:03 AM
Post #2

D.I.C Head
Group Icon

Joined: 6 Sep, 2008
Posts: 122



Thanked: 2 times
Dream Kudos: 100
My Contributions
Ok first and foremost - ALWAYS post your code with the appropriate tags.

To answer your problem tho, when you see LNK in your errors, it has something to do with the way you're using anything above main. In your case, you made the definition for your DrawGallons() function inside of main, which is not allowed. Also, when you made the definition inside of main, you used a semicolin after the header (also illegal).

So to fix: take out your system(pause) and return 0 and put it at the end of your main. Below main, define your function definitions with no semicolin after them.

The other warning you're getting are because of the way you're trying to "draw" your guy on the screen, and the compiler thinks you're using an escape sequence

Also, you like to put random blocks of code everywhere, and I'd definitely stay away from that. Generally, you should flow you're programs like this:

cpp

// include files up here

// structures, function declarations could go here
// or in a separate header file
void Function1( int x );

int main( void )
{
// create objects
int variable;

// block of main
Function1( variable );

// great success!
return 0;
}

// function definitions here
void Function1( int x );
{
// body of function
cout << "x: " << x << endl;
}


Hope this helps! smile.gif

This post has been edited by Psionics: 28 Sep, 2008 - 06:10 AM
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/3/08 12:39AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month