Boolean logic troubles?

Hi everybody, here's a sample program I wrote to show you what I don't understand. I'm making the user input an element from the periodic table, but I want it not to be case-sensitive, so I used an if statement and the logical operation OR to do this, but I don't understand why it doesn't work.

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
#include <iostream>

using namespace std;

class Table
{
    public:

    void display(string name, int atomicnumber)
    {
        cout<<"Element: "<<name<<"\n";
        cout<<"Atomic Number: "<<atomicnumber<<"\n";
    }
};

int main()
{
    Table Hydrogen;

    cout<<"Enter an element to see its atomic number.\n\n";
    for(;;)
    {
        string element;
        cout<<"Enter element here: ";
        cin>>element;

        if (element == "Hydrogen" || "hydrogen")
        {
            Hydrogen.display("Hydrogen", 1);
        }

        else if (element == "stop")
        {
            break;
        }
    }
}


When I input something (like "stop"), it always executes what's in the first if statement, but it works fine without the || "hydrogen". I know this is probably a noobish question but could someone explain this?
The correct syntax should be as you highlighted.

if (element == "Hydrogen" || element == "hydrogen")
Oh, I actually knew that, wow, I feel stupid, well thanks anyway sohguanh.
Topic archived. No new replies allowed.