Regardless of what value I input the while statement won't recognize the input as matching either of the three predetermined values. I am very new to this... What am I doing wrong?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
string po1;
string po2;
string poExercise;
cout << "Which lift(s) would you like to perform progressive overload on?" << endl;
cout << "Type 'squat', 'bench' or 'deadlift'." << endl;
cin >> po1;
while ((po1 != "squat") || (po1 != "bench") || (po1 != "deadlift"))
{
cout << "Your input was invalid." << endl;
cout << "Which lift(s) would you like to perform progressive overload on?" << endl;
cout << "Type 'squat', 'bench' or 'deadlift'." << endl;
cin >> po1;
}
How would I write this to check that the string matches one of those three values and if it doesn't to keep making them input it until they get it right? If that is going to be a lot more complex I can just provide a list of numbers and have them choose that way. I was trying to figure this out though.
NVM I just replaced them with &&. I am not very good at intuiting this process.
Thanks Seeplus for the link about DeMorgan laws. Interesting short reading...
1 2 3 4 5
// it's running in all cases because you misunderstood || (or) and && (and)
// whatever your entry , it corresponds to all possible variants :/
while ((po1 != "squat") || (po1 != "bench") || (po1 != "deadlift"))
// it's running until you enter one of these three entries
while (po1 != "squat" && po1 != "bench" && po1 != "deadlift")
However, as mentioned Seeplus, for me the most readable condition will be this one :
1 2
// only one of these entries can break the condition
while (!(po1 == "squat" || po1 == "bench" || po1 == "deadlift"))