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,925 people online right now. Registration is fast and FREE... Join Now!




hangman main void error

 
Reply to this topicStart new topic

hangman main void error

villalandron
26 Sep, 2008 - 03:09 PM
Post #1

New D.I.C Head
*

Joined: 24 Sep, 2008
Posts: 23

I am puzzled about this. I am writing a hangman code and I receive a error I don't understand. Can somebody please explain me why am I getting this error? I did this code exactly like it said in a tutorial. Here's the program:
cpp

#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];
int count;

void main()
{
char choice, Yes;
char Continue = Yes;
int State;

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 here are the error messages:

1>hangman.cpp
1>.\hangman.cpp(122) : warning C4129: ' ' : unrecognized character escape sequence
1>.\hangman.cpp(123) : warning C4129: ' ' : unrecognized character escape sequence
1>.\hangman.cpp(134) : warning C4129: ' ' : unrecognized character escape sequence
1>.\hangman.cpp(135) : warning C4129: ' ' : unrecognized character escape sequence
1>.\hangman.cpp(145) : warning C4129: ' ' : unrecognized character escape sequence
1>.\hangman.cpp(185) : error C2562: 'main' : 'void' function returning a value
1> .\hangman.cpp(16) : see declaration of 'main'
1>Build log was saved at "file://c:\Users\Julio\Documents\Visual Studio 2008\Projects\hangman\hangman\Debug\BuildLog.htm"
1>hangman - 1 error(s), 5 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ===


Thank You for your help! I have learned a lot more about C++ in the past 3 days by using this website than by reading my courseware book for one week. I try to make the code, I get the errors and get stuck. I try many different approaches and receive proper advices from experts on how to do it properly in order to be able to lick my wounds. The book have examples that have similar programs but are not the same. Again, thank you!

EDIT: code.gif

This post has been edited by William_Wilson: 26 Sep, 2008 - 03:42 PM
User is offlineProfile CardPM
+Quote Post

William_Wilson
RE: Hangman Main Void Error
26 Sep, 2008 - 03:44 PM
Post #2

lost in compilation
Group Icon

Joined: 23 Dec, 2005
Posts: 3,995



Thanked: 16 times
Dream Kudos: 3275
Expert In: Java, C, Javascript

My Contributions
the \ symbol is an escape character, you need to escape IT to use it: "\" is incorrect, "\\" is correct.
User is offlineProfile CardPM
+Quote Post

Bench
RE: Hangman Main Void Error
27 Sep, 2008 - 02:47 AM
Post #3

D.I.C Addict
Group Icon

Joined: 20 Aug, 2007
Posts: 624



Thanked: 15 times
Dream Kudos: 150
Expert In: C/C++

My Contributions
you're getting that error because you have specified void as the return type of your main() function, and the compiler is correctly telling you that main needs to return an int (this allows you to return 0 from main as you have done at the end of your main function)

CPP
int main()
ought to compile correctly, and must always be used instead of void.

This post has been edited by Bench: 27 Sep, 2008 - 02:48 AM
User is offlineProfile CardPM
+Quote Post

villalandron
RE: Hangman Main Void Error
27 Sep, 2008 - 06:08 AM
Post #4

New D.I.C Head
*

Joined: 24 Sep, 2008
Posts: 23

QUOTE(Bench @ 27 Sep, 2008 - 03:47 AM) *

you're getting that error because you have specified void as the return type of your main() function, and the compiler is correctly telling you that main needs to return an int (this allows you to return 0 from main as you have done at the end of your main function)

CPP
int main()
ought to compile correctly, and must always be used instead of void.


Ok, I changed the void main to int main and now I get more errors. Here they are:

1>hangman.cpp
1>.\hangman.cpp(127) : warning C4129: ' ' : unrecognized character escape sequence
1>.\hangman.cpp(128) : warning C4129: ' ' : unrecognized character escape sequence
1>.\hangman.cpp(139) : warning C4129: ' ' : unrecognized character escape sequence
1>.\hangman.cpp(140) : warning C4129: ' ' : unrecognized character escape sequence
1>.\hangman.cpp(150) : warning C4129: ' ' : unrecognized character escape sequence
1>c:\users\julio\documents\visual studio 2008\projects\hangman\hangman\hangman.cpp(24) : warning C4700: uninitialized local variable 'Yes' used
1>c:\users\julio\documents\visual studio 2008\projects\hangman\hangman\hangman.cpp(63) : warning C4700: uninitialized local variable 'Word' used
1>c:\users\julio\documents\visual studio 2008\projects\hangman\hangman\hangman.cpp(120) : warning C4700: uninitialized local variable 'State' 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), 9 warning(s)
User is offlineProfile CardPM
+Quote Post

red_4900
RE: Hangman Main Void Error
27 Sep, 2008 - 07:00 AM
Post #5

Code Dreamers
****

Joined: 22 Feb, 2008
Posts: 820



Thanked: 11 times
My Contributions
did you try William Wilson explanation?
User is online!Profile CardPM
+Quote Post

gabehabe
RE: Hangman Main Void Error
27 Sep, 2008 - 07:22 AM
Post #6

Donkey DIC
Group Icon

Joined: 6 Feb, 2008
Posts: 5,539



Thanked: 98 times
Dream Kudos: 2650
Expert In: ruling the world.

My Contributions
Just reading your errors quickly, you'r using variables which haven't been defined. Namely Yes, Word, and State.

You have to give them a type in order to use them.
User is online!Profile CardPM
+Quote Post

villalandron
RE: Hangman Main Void Error
27 Sep, 2008 - 08:44 AM
Post #7

New D.I.C Head
*

Joined: 24 Sep, 2008
Posts: 23

QUOTE(William_Wilson @ 26 Sep, 2008 - 04:44 PM) *

the \ symbol is an escape character, you need to escape IT to use it: "\" is incorrect, "\\" is correct.



Can you expand a little more? I kind of don't understand. I'm a newbie to C++. Thank You!

QUOTE(villalandron @ 27 Sep, 2008 - 09:40 AM) *

QUOTE(William_Wilson @ 26 Sep, 2008 - 04:44 PM) *

the \ symbol is an escape character, you need to escape IT to use it: "\" is incorrect, "\\" is correct.



Can you expand a little more? I kind of don't understand. I'm a newbie to C++. Thank You!



This is how my code looks like:

cpp
#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!

MOD EDIT: Please code.gif
User is offlineProfile CardPM
+Quote Post

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

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