For Loops messing up

I am trying to make a part of the game hangman, where the user inputs a letter and then a loop check for that letter in a random array. If the letter is found, it then couts it, but if it is not there, then it couts << " _ ", as in blank. This is for a hangman game and offers the user to again, input another letter. It seems for loops are not wworking since the output here is:

Enter a Letter: 
a
 _ Enter a Letter: 
 _ Enter a Letter: 
00000Enter a Letter: 
 _ Enter a Letter: 
 _ Enter a Letter: 
 _ Enter a Letter: 
00000Enter a Letter: 
00000Program ended with exit code: 0

my code is not working properly and I don't know why.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
 for(int v = 0; v < 8; v++){
        
        cout << "Enter a Letter: " << endl;
        cin >> ugib[v];
        
        if(ugib[v] == geslo[v]){
            for(int b = 0; b < 5; b++){
                cout << ugib[v];
            }
        }
        else{
                cout << " _ ";
            }
    }

Can anyone help me with the code, i dont know what I am doing wrong. thanks.
Last edited on
I'm guessing you probably want to read the character in before you go into the for loop.
On line 12, after you cout a blank, you need to add a newline so that the next output gets displayed in a new line.

So I guess that after you cout a "_" add endl;.
Or you can also add an endl; before line 3 when you ask user to "Enter a Letter".
Last edited on
Topic archived. No new replies allowed.