Sorry, this code seems silly but I just want to get the logic.
I am trying to end the program when the user enters quit as an input.
I wrote name != "quit" && sname != "quit" as the while condition, so if any of them is quit, the loop would end (right?).
But when I write quit as name, it still waits for sname input, if I write quit also for the sname input, then it finally ends. But shouldn't it end when it see quit for the very first time since I wrote the conditions with &&?
In addition, I get the same output when I wrote the condition with ||. Why is this so?
int main() { string name="",sname=""; cout << "enter your name and surname \n"; cout << ">>name="; getline(cin,name); cout << ">>surname="; getline(cin,sname); while (name != "quit" && sname != "quit") { cout << ">>name="; getline(cin,name); cout << ">>surname="; getline(cin,sname); } return 0; } Output:
enter your name and surname >>name=John >>surname=Wick >>name=quit >>surname=