having error in this code...

when I compile this code it gives error statment missing ; atline number 43..Can any one correct it for me.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#include<graphics.h>
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
void main(void)
{
int gdriver=DETECT,gmode;
initgraph(&gdriver,&gmode,"C:\\turboc3\\bgi");
ellipse(320,95,360,0,25,20);
line(298,85,341,85);
circle(310,90,2);
circle(330,90,2);
arc(320,100,200,-20,10);
line(313,115,313,125);
line(328,115,328,125);
arc(320,225,72,107,100);
line(290,129,290,200);
line(350,129,350,200);
line(290,193,350,193);
line(290,200,350,200);
line(290,200,285,280);
line(320,225,305,280);
line(322,225,335,280);
line(350,200,355,280);
line(350,129,385,165);
line(385,165,350,200);
line(350,149,365,165);
line(365,165,350,182);
line(290,129,255,165);
line(255,165,290,200);
line(290,149,275,165);
line(275,165,290,182);
line(285,280,275,287);
line(275,287,305,287);
line(305,280,305,287);
line(335,280,335,287);
line(335,287,365,287);
line(355,280,365,287);
cout<<"ESCAPE ISLAND"<<endl;
main()
{
int wrong;
string THE_WORD,soFar,bool,used;
bool match(char letter,string word);
char askguess(string usedletterstr);
bool play again();
main()
{
srand(time(0));
vector<string> words;
words.push_back("encyclopedia");
words.push_back ("constitution");
words.push_back("government");
word.push_back("kidding");
words.push_back("standard");
words.push_back("firewall");
words.push_back("terror");
words.push_back("profession");
words.push_back("donation");
words.push_back("xerox");
words.push_back("victory");
words.push_back("dentistry");
words.push_back("zodiac signs");
cout<<"Welcome to Hangman-Good luck!\n";
bool done=false;
do
{
const int MAX_WRONG=8;
random_shuffle (words.begin(),words.end());
THE_WORD=word[0];
soFar= (THE_WORD.size(),'-');
used="";
while((wrong<MAX_WRONG)&&(soFar!=THE_WORD))
{
cout<<"\n\n you have "<<MAX_WRONGS-wrong <<"incorrect guesses left\n";
cout<<"\n you have used the following letters :\n"<<used<<endl;
cout<<"\n soFar,the word is:\n"<<soFar<<endl;
used+=ask guess(used);
while(wrong<MAX_WRONGS&& soFar!= THE-WORD)
if(wrong==MAX_WRONG)
{
cout<<"you have been hanged!"<<endl;
}
cout<<"\n the word was "<<THE_WORD<<endl;
}
while(play again());
return0;
}
inline boolmatch(char letter, string word);
{
return(word.find(letter)!=string ::npos);
}
char askguess(string usedletterstr);
{
char guess;
cout<<"\n\n enter guess:";
cin>>guess;
guess=toupper(guess);
while(match(guess.used))
{
cout<<"\n you have already guessed"<<guess<<endl;
cout<<"enter your guess:";
cin>>guess;
guess=toupper(guess);
}
if(match(guess.THE_WORD))
{
cout<<"that's right!"<<guess<<"is in the word \n";
for(int i=0;i<THE WORD.lenght();i++)
if(THE_WORD[i]==guess)
soFar[i]=guess;
}
else
{
cout<<"sorry,"<<guess<<"is not in the word\n";
++wrong;
}
}
bool play again();
{
char again;
cout<<"\n would u like to play again<y/n>:";
cin>>again;
cin.clear();
cin.ignore();
again=toupper(again);
system (cls);
return (again=='Y');
}
getch();
closegraph();
}
}
}
}
Last edited on
The best way to do this is to format your code.

Seems to me you have a extra } at the end but there may be other problems that will appear when you look at it formatted.

kindly guide me regarding it's formatting...I have tried hard to remove this error but failed... or if u can point out the particular error...
Could you please, use the code tags? (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your
post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <>
formatting button.
done..kindly can u help me now??
closed account (E0p9LyTq)
Why do you have multiple main() functions? One void main(void) and two main().

None of the three are legal modern standard C++ main() functions.

By the look of your header includes you seem to be using an older compiler. The standard is #include <iostream> , not #include <iostream.h> .
closed account (E0p9LyTq)
Your code even with code tags is horribly formatted, which makes it very hard to read.
now what should I do???...... that is the problem...if i remove any one of main()...it gives me lots of errors...and I am using turbo C++
Last edited on
now what should I do???


Did you write this code? What have you learned on C++, so far? It looks like you are trying to do a hangman game. Why don't you try to do it without the graphics library first and use the C++ syntax?
I would recommend to work on your pseudocode of your program. Also, work on the formatting your code. It looks that you are trying to do too many things, at once. The legal modern standard in C++ is only one int main(). If I were you, I will try to go over on the parts of the C++ program. You have so many errors on this code. For example,
1
2
bool match(char letter,string word);
char askguess(string usedletterstr);

When I look at it, I would say they are function prototypes. However, they are inside one of your main() function, so I assume you are performing a function call. Nevertheless, I try to look for the function definitions, but I could not find it.
What I do in situations like this, I step back and start working the code a little bit at the time and debugging it during the process. I tried to look at your code to give more help, but there are more questions than answers. Good luck on working on your code.
actually i am new to C++... if u could just explain me in easy words...I am unable to get u.. Many thankx ..
Last edited on
actually I am planning to connect two or three things and make a innovative game.. like I have printed a man with the help of code and then wrote a code for hangman so that If user types a correct word the man is happy and get points and if user is unable to guess the correct word..the printed man seems to be hanged..kindly guide me..
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#include<graphics.h>
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
{
main()
{
int gdriver=DETECT,gmode;
initgraph(&gdriver,&gmode,"C:\\turboc3\\bgi");
ellipse(320,95,360,0,25,20);
line(298,85,341,85);
circle(310,90,2);
circle(330,90,2);
arc(320,100,200,-20,10);
line(313,115,313,125);
line(328,115,328,125);
arc(320,225,72,107,100);
line(290,129,290,200);
line(350,129,350,200);
line(290,193,350,193);
line(290,200,350,200);
line(290,200,285,280);
line(320,225,305,280);
line(322,225,335,280);
line(350,200,355,280);
line(350,129,385,165);
line(385,165,350,200);
line(350,149,365,165);
line(365,165,350,182);
line(290,129,255,165);
line(255,165,290,200);
line(290,149,275,165);
line(275,165,290,182);
line(285,280,275,287);
line(275,287,305,287);
line(305,280,305,287);
line(335,280,335,287);
line(335,287,365,287);
line(355,280,365,287);
cout<<"ESCAPE ISLAND"<<endl;
int wrong;
string THE_WORD,soFar,bool,used;
bool match(char letter,string word);
char askguess(string usedletterstr);
bool play again();
srand(time(0));
vector<string> words;
words.push_back("encyclopedia");
words.push_back ("constitution");
words.push_back("government");
word.push_back("kidding");
words.push_back("standard");
words.push_back("firewall");
words.push_back("terror");
words.push_back("profession");
words.push_back("donation");
words.push_back("xerox");
words.push_back("victory");
words.push_back("dentistry");
words.push_back("zodiac signs");
cout<<"Welcome to Hangman-Good luck!\n";
bool done=false;
do
{
const int MAX_WRONG=8;
random_shuffle (words.begin(),words.end());
THE_WORD=word[0];
soFar= (THE_WORD.size(),'-');
used="";
while((wrong<MAX_WRONG)&&(soFar!=THE_WORD))
{
cout<<"\n\n you have "<<MAX_WRONGS-wrong <<"incorrect guesses left\n";
cout<<"\n you have used the following letters :\n"<<used<<endl;
cout<<"\n soFar,the word is:\n"<<soFar<<endl;
used+=ask guess(used);
while(wrong<MAX_WRONGS&& soFar!= THE-WORD)
if(wrong==MAX_WRONG)
{
cout<<"you have been hanged!"<<endl;
}
cout<<"\n the word was "<<THE_WORD<<endl;
}
while(play again());
return0;
}
inline boolmatch(char letter, string word);
{
return(word.find(letter)!=string ::npos);
}
char askguess(string usedletterstr);
{
char guess;
cout<<"\n\n enter guess:";
cin>>guess;
guess=toupper(guess);
while(match(guess.used))
{
cout<<"\n you have already guessed"<<guess<<endl;
cout<<"enter your guess:";
cin>>guess;
guess=toupper(guess);
}
if(match(guess.THE_WORD))
{
cout<<"that's right!"<<guess<<"is in the word \n";
for(int i=0;i<THE WORD.lenght();i++)
if(THE_WORD[i]==guess)
soFar[i]=guess;
}
else
{
cout<<"sorry,"<<guess<<"is not in the word\n";
++wrong;
}
}
bool play again();
{
char again;
cout<<"\n would u like to play again<y/n>:";
cin>>again;
cin.clear();
cin.ignore();
again=toupper(again);
system (cls);
return (again=='Y');
}
getch();
closegraph();
}
}

I removed rest of main() and put only one... now it gives 1 error in line 7..i.e declaration terminated incorrectly
can any one help me to remove this error plzz...??
As someone said above, go back and check your includes.

line 7 should be removed.

line 8 should be
int main()
or
void main()

 
return 0;
should be at the end of your main statement.

You have no comments in your code to describe what anything does...

Formating means to line up your code so that it's easy to read
such as

1
2
3
4
5
6
7
8
if (true)
   {
    // some code
   }
else
   {
   // do something else
   }


Those are the most basic of things. Until you learn the basics, your going to have trouble and no one wants to help because it's hard to read. No one wants to format your code for you, it's so basic you should already know that and save us time and effort by doing it before posting it here. When you format your code, errors have a way to show up easier. You'll be amazed...
Last edited on
Topic archived. No new replies allowed.