Simple Hangman game - guess checking not working

I am trying to create a simple hangman game with the word "ROBOT". I'm still an early beginner, so I am trying to hardcode it. The problem that I am running into, is that the guess checking section:

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
if (guess == ("R" || "r"))
            {
                L1 = "R";
                i++;
            }

            else if (guess == ("O" || "o"))
            {
                L2 = "O";
                L4 = "O";
                i++;
            }

            else if (guess == ("B" || "b"))
            {
                L3 = "B";
                i++;
            }

            else if (guess == ("T" || "t"))
            {
                L5 = "T";
                i++;
            }

            else
            {
                cout << "Incorrect! Please Try again.";
                cout << i << " tries left.";
            }


It doesn't register the correct letter as being correct. No matter what I put, it results in "Incorrect! Please Try again." and a lose of a try, even if it is one of the correct answers.

Here is the full code:
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
61
62
63
64
65
66
67
68
69
70
71
72
#include <iostream>
#include <string>

using namespace std;

string L1 = "_";
string L2 = "_";
string L3 = "_";
string L4 = "_";
string L5 = "_";
char guess;
int i;

void standing ()
{
    cout << L1 << " " << L2 << " " << L3 << " " << L4 << " " << L5;
}

int main ()
{
    cout << "This is a 5 letter hangman game. You can make 6 errors before losing. Choose a letter and goodluck!" << endl;
    standing ();
    cout << endl;

    while (true)
    {
        for (i = 7; i > 0; i--)
        {
            cout << "Please enter a letter.";

            if (((((L1 == "R") && L2 == "O") && L3 == "B") && L4 == "O") && L5 == "T")
            {
                cout << "Congratulations! You've won the game!";
                return 0;
            }
            cin >> guess;
            if (guess == ("R" || "r"))
            {
                L1 = "R";
                i++;
            }

            else if (guess == ("O" || "o"))
            {
                L2 = "O";
                L4 = "O";
                i++;
            }

            else if (guess == ("B" || "b"))
            {
                L3 = "B";
                i++;
            }

            else if (guess == ("T" || "t"))
            {
                L5 = "T";
                i++;
            }

            else
            {
                cout << "Incorrect! Please Try again.";
                cout << i << " tries left.";
            }
        }
        cout << "You lose mofo!";
        return false;
    }
}
closed account (Dy7SLyTq)
your problem is your hardcoding it. what you want is to have a list a words either hardcoded into an array or get it off a list. and then get the size of the word, and put out that many *'s. then in a while loop get input see if the letter the user said is in the word, if it is, replace each star that the letters at. if not do what ever you want to do for them getting it wrong.
Topic archived. No new replies allowed.