Hangman

I'm a beginner in programming, just started to work in some projects and one of them is a "CANT WIN HANGMAN GAME" and need help finishing it. This is what I have at this time:

My gallows.h file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#ifndef GALLOWS_H
#define GALLOWS_H
#include <iostream>
using namespace std;

class GallowsPole			
{							
public:
	GallowsPole();
	~GallowsPole();
	int counter();
	void draw0();											
	void draw1();
	void draw2();
	void draw3();
	void draw4();
	void draw5();
	void draw6();
	
private:	
		int count;	
};
#endif 


My gallows.cpp file:
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#include <iostream>
#include <fstream>
#include "gallows.h"

using namespace std;

// define your methods here


GallowsPole::GallowsPole()
{count=0;
}
GallowsPole::~GallowsPole(){}
int GallowsPole::counter()
{
	int tries,guess;
	char letter;
	tries=6;
	guess=0;
	

	do  
	{
		if (guess==0)
		{
			cout<<"HANGMAN"<<endl<<"YOU WON'T WIN"<<endl;
			cout<<"START"<<endl<<"YOU HAVE 6 TRIES"<<endl<<"Make your first guess: "<<endl;
			cin>>letter;
			guess++;
			//guess=count;
		}
		else if(guess==1)
		{
			cout<<"Make your second guess: "<<endl;
			cin>>letter;
			guess++;
			//guess=count;
		}
		else if (guess==2)
		{
			cout<<"Make your third guess: "<<endl;
			cin>>letter;
			guess++;
			//guess=count;
		}
		else if (guess==3)
	{
		cout<<"Make your fourth guess: "<<endl;
		cin>>letter;
		guess++;
		//guess=count;
	}
		else if (guess==4)
		{
			cout<<"Make your fifth guess: "<<endl;
			cin>>letter;
			guess++;
			//guess=count;
		}

		else if (guess==5)
		{
			cout<<"Make your sixth and last guess!: "<<endl;
			cin>>letter;
			guess++;
			//guess=count;
		}

		else if (guess==6)
		{
			cout<<"YOU LOST"<<endl;
			//guess=count;
			break;
			system("PAUSE");
		}
	}
while (guess !=7);

	return count;
}

/*
void GallowsPole::draw0()
{
    cout << " _____  " << endl;
    cout << " |   |  " << endl;
    cout << " |      " << endl;
    cout << " |      " << endl;
    cout << " |      " << endl;
    cout << " |      " << endl;
    cout << "--------" << endl;
}

void GallowsPole::draw1()
{
    cout << " _____  " << endl;
    cout << " |   |  " << endl;
    cout << " |   O  " << endl;
    cout << " |      " << endl;
    cout << " |      " << endl;
    cout << " |      " << endl;
    cout << "--------" << endl;
}

void GallowsPole::draw2()
{
    cout << " _____  " << endl;
    cout << " |   |  " << endl;
    cout << " |   O  " << endl;
    cout << " |   |  " << endl;
    cout << " |      " << endl;
    cout << " |      " << endl;
    cout << "--------" << endl;
}

void GallowsPole::draw3()
{
    cout << " _____  " << endl;
    cout << " |   |  " << endl;
    cout << " |   O  " << endl;
    cout << " |  /|  " << endl;
    cout << " |      " << endl;
    cout << " |      " << endl;
    cout << "--------" << endl;
}

void GallowsPole::draw4()
{
    cout << " _____  " << endl;
    cout << " |   |  " << endl;
    cout << " |   O  " << endl;
    cout << " |  /|\ " << endl;
    cout << " |      " << endl;
    cout << " |      " << endl;
    cout << "--------" << endl;
}

void GallowsPole::draw5()
{
    cout << " _____  " << endl;
    cout << " |   |  " << endl;
    cout << " |   O  " << endl;
    cout << " |  /|\ " << endl;
    cout << " |  /   " << endl;
    cout << " |      " << endl;
    cout << "--------" << endl;
}

void GallowsPole::draw6()
{
    cout << " _____  " << endl;
    cout << " |   |  " << endl;
    cout << " |   O  " << endl;
    cout << " |  /|\ " << endl;
    cout << " |  / \ " << endl;
    cout << " |      " << endl;
    cout << "--------" << endl;
}
*/


And my main .cpp file:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>

using namespace std;

#include "gallows.h"

int main()
{
	int a;
	GallowsPole g;
	a=g.counter();

	system("PAUSE");
	return 0;
}


Up to now the program asks the user for 6 guesses, but I'm having trouble figuring out how to keep count of the tries in order to display my void draw methods!

Please any help will be aprreciated
Last edited on
why not put the draw method which corresponds to the guess number within the guess block?

1
2
3
4
5
6
7
8
else if (guess==6)
		{
			cout<<"YOU LOST"<<endl;
                        draw6();  //draw the last one.
			//guess=count;
			break;
			system("PAUSE"); //the is pointless... the system breaks before it ever reaches there.
		}
Last edited on
Well thank you pogrady! Works fine now!
Better to create public GallowsPole::draw() method which will call draw0()–draw6() methods based on private variable and make draw0()–draw6() methods private.
Topic archived. No new replies allowed.