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.
#include <iostream>
usingnamespace 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);
}
elseif (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?