I am running a series of if
/ else if
/ else
statements using strings, and regardless of the user input the if
is always returning true:
cout << "Enter the element to look up: ";
cin >> elementLookup;
cout << endl << endl;
if (elementLookup == "H" || "Hydrogen" || "hydrogen") {
cout << "Atomic Number: " << H_NUMBER << endl << endl;
cout << "Atomic Mass: " << H_MASS << endl << endl;
}
else if (elementLookup == "He" || "Helium" || "helium") {
cout << "Atomic Number: " << HE_NUMBER << endl << endl;
cout << "Atomic Mass: " << HE_MASS << endl << endl;
}
else if (elementLookup == "Li" || "Lithium" || "lithium") {
cout << "Atomic Number: " << LI_NUMBER << endl << endl;
cout << "Atomic Mass: " << LI_MASS << endl << endl;
}
All of the variables have been declared earlier in the code. For some reason, every time I run this code it says the first if statement is true, regardless of user input. What am I doing wrong"