SIMPLE CONSOLE GAME - PROBLEM STUCK NEED HELP

Hey guys, I am very new to C++.
I created this console game sort of like Hangman type with little to no reference/help at all. But I have now been stuck for an hour trying to get it to work right but I admit defeat. It has a small bug that I cannot seem to find a solution for. :(

PROBLEM:

The hangman word answer is BOB.
When I play the game I enter the letter B. It should reveal B*B but it does not. It just reveal B** instead. I think it is to do with my loop but I just don't know how to get it to reveal right. Could someone please help? I have a feeling it is something simple but I am stuck.



Thanks.




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
void init()
{
	char hidden[4] = { '*','*','*','\0' };
	char word[4] = { 'B','O','B','\0' };
	char guess;

	cout << "WORD IS: " << hidden << endl;
	cout << "Select a letter from the list: B O S E T B" << endl << endl;


	for (int i = 0; i <sizeof(word); i++)
	{

		cin >> guess;

		if (guess == word[i]) 
		{

			hidden[i] = word[i];
		}
		else
		{
			i--;
		}


		cout << "WORD IS: " << hidden << endl;
	}

}






Last edited on
Stop shouting in your title.
Perhaps move your cin >> guess to before the for loop. And why are you decrementing i?
You need a inner loop where you compare the letters with the guess. The outer loop is for the guess itself. Maybe you want to allow more guess than the number of letters.
Topic archived. No new replies allowed.