Help with counter

So i've made a big function that will handle the main game mechanics.
Lets say that the word is 'excellent'.
Right now it will output: _ _ _ _ _ _ _ _ _ Guess a word: e

"You guessed: 'e'"
"'e' was found at position: 0."
"Correct guesses: 1"

"e _ _ e _ _ _e_ _ Guess a word: "

What I want to do is that the position will say: 0, x, x, if there is more than one char in the word.
And that correctGuesses will in this example hold 3. I know that 'correctGuesses' is the wrong word.. because it's true that I just made one guess. But you guys get the point.
I've tried different ways to solve this with no luck.

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
void playS()
{
	char guess;
	size_t found;
	
	std::string word = randomWord();

	std::ifstream file("words.txt");
	  
	while (file.is_open())
    {
	  
     	std::vector<int> correctGuesses;
		std::vector<int> wrongGuesses;

		while(word.length() > 0)
		{
				
				for(unsigned int i = 0; i < word.length(); i++)
				{
					bool guess_ok = false;

				for(unsigned int j = 0; j < (int)correctGuesses.size(); j++)
				{
					guess_ok = (word[i] == correctGuesses[j]);
				
					if(guess_ok)
					{
						std::cout << word[i];
						break;
					}
			
				}
					if(! guess_ok)
						std::cout << " _ "; 
				}
		
				std::cout << "Please guess a char: ";
			    std::cin >> guess;
			    std::cout << "\nYou guessed: " << guess << "\n\n";
				found=word.find(guess);

		if(int(found) != std::string::npos)
		{
			correctGuesses.push_back(guess);
			std::cout << "'" << guess << "'" << " was found at position: " << int(found) << "\n";
			std::cout << "Correct guesses: " << correctGuesses.size() << "\n";
		}
		else
		{
			std::cout << "sorry nope!\n";
			wrongGuesses.push_back(guess);
			std::cout << "\nwrongGuesses holds: " << wrongGuesses.size() << " char/s.\n";
	    }
	 }

    file.close();
	}
}

bump.
You need to turn the type 'found' int vector<int>

on line 41 you can use the same loop like on line 19. if the guess matches just push_back the guess.

on line 46 you have additionally a loop that prints the elements of the found vector
Topic archived. No new replies allowed.