Just a slight bit of help.

So im currently working on a hangman game and was wondering if i could just get a little help into which direction to go from where i am. I am stumped.

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
#include <iostream>
#include <string>
using namespace std;

const int maxIndex = 100;
typedef int IntArrayType[maxIndex];

string gameSearch(char&, int, string&);
void getInitWord(string&, int&, string&);
void guessWord(char&, string&, int);
void solution(string&);

int main ()
{	
	string word;
	string finalGuess;

	int tries;
	char guess;
	string solution = "";

	getInitWord(word, tries, solution);
	finalGuess = word;

	while(tries != 0)
	{
		guessWord(guess, word, tries);
		cout << solution;
		gameSearch(guess, tries, word);

	}	
}

void getInitWord(string& w, int& numOfTries, string& solution)
{
	cout << "Enter the word to be guessed: ";
	cin >> w;
	cout << "Enter the max number of tries: ";
	cin >> numOfTries;

	string star = "*";
	int solSize = w.size();
		for(int i=0; i < solSize; i++)
		{
			solution = solution + star;
		}
}

string gameSearch(char& guess, int Count, string& Target)
{
	return 0;

}

void guessWord(char& letter, string& word, int tries)
{
	cout << "Guess a letter (You have " << tries << " left): ";
	cin >> letter;

}
Last edited on
I'd say that your next step is to fill out the gameSearch function.

check if the guessed letter is contained in the string as this is where the program crashes right now. I'm not sure what you want to return. But I'm guessing you want to return your string with the stars. Just replace the starts with the correct letter.

1
2
3
4
string gameSearch(char& guess, int &Count, string& Target)
{
	return 0; // it should return a string, not 0.
}

Topic archived. No new replies allowed.