Hangman code trouble

i have been given an assignment my my university to make a hangman game, and for the most part i have done that, unfortunately i am having a lot of issues with my guess checking, for some reason (probably due to my terrible programming) it only checks the first letter of the word against the guessed letter, is there anyway to fix my code.
please be patient with me i haven't been doing this all that long and its been a very long day

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
 
while (lives > 0)
{
		
		std::cout<< word; // help with testing (so i can see what word has been picked)

		std::cout<<"\t \t please enter your guess"<<std::endl;
		std::cin>> guess;

		for(int i = 0; i < strlen(word); i++)		//checking letter input against the word 
	{
		int c = word[i];
		if(c == 0)
		{
			break;
		}

		if (guess == c)
		{
			std::cout<<"that is correct"<<std::endl;
			std::cout<<"you have"<<lives<<"remaining"<<std::endl;
			break;
		}
		else 
		{
			std::cout<<" that is incorrect"<<std::endl;
			std::cout<<"you have"<<lives<<"remaining"<<std::endl;
			break;
		}
	}
		
		
} 
if ( c == 0 ) .it should be if ( c == '0' )
if the first two statement is false then the else statement will be executed which has a break statement which will stop the loop.
in others word, if the guess didnt hit the first letter of the word the loop will be stopped.
try something like this.
1
2
if ( lives decreased by 1 ) 
stop the loop;
Last edited on
Topic archived. No new replies allowed.