First off, welcome to the C++ world! Now, let’s move onto your problem. If you take a look at this line,
while (name != "Alice" || name!= "Bob")
As others have said, this contains the problem. You are basically saying:
while (the name is NOT "Alice" OR the name is NOT "Bob")
Names cannot be two things at once. In order to hit this condition, your name will have to be Bob Alice or Alice Bob. If you look at the following line of code
std::cin >> name;
This will be impossible. The computer is only taking one word. The condition will never hit. In order to fix this, you should do the following:
while (name != "Alice" && name != "Bob")
That will fix the problem. Also, if you would like to improve your code, you can do the following:
#include <iostream>
#include <string>
int main()
{
std::string name = "";
std::cout << "Please enter the correct name: ";
std::cin >> name;
while (name != "Alice" && name != "Bob")
{
std::cout << "Please enter the correct name: ";
std::cin >> name;
}
std::cout << "Hi " << name << "!" << endl;
2
solved Using a string in a while loop (OR operator)