I'm doing a conversion between units, but when I try to check if the user enters the right input, I always get the error for invalid unit..
If I use just one of the units in the while(or if) arguments like this:
while(unit!="m"), it works just fine.
I thought the "||" operator would make this work for all units, but I guess I have misunderstood how it works.
1 2 3 4 5 6 7 8 9 10
double one;
string unit;
do {
cout << "Write a number and a unit('m', 'cm', 'in', 'ft')" << endl;
cin >> one >> unit;
cout << "'" <<unit<< "'" << endl; //Just to see if I enter the right unit
if (unit != "m" || unit != "cm" || unit != "in" || unit != "ft") {
cout << "Invalid unit" << endl;
}
} while ((unit != "m") || (unit != "cm") || (unit != "in") || (unit != "ft"));