My code is not working?

I have this code to redirect to the home if it doesnt equal any of these. Whatever you put in it will output "Sorry, this is not a valid answer, please try again"

1
2
3
4
5
if(Answer!=("Home","Shop","Fight")){
cout << "Sorry, this is not a valid answer, please try again!";
Sleep(1000);
Answer="Home";
}
That syntax on line 1 is legal C++, but it almost certainly isn't doing what you want to do. Do you understand what the comma operator actually does in C++?
1
2
3
4
5
6
if (Answer == "Home" || Answer == "Shop" || Answer == "Fight"){
	//do something
} else {
	cout << "Sorry, this is not a valid answer, please try again!" << endl;
	Answer = "Home";
}
thx, this worked for me
Nevermind my last post, this is closer to the OP
1
2
3
4
5
if (Answer != "Home" && Answer != "Shop" && Answer != "Fight"){
	cout << "Sorry, this is not a valid answer, please try again!" << endl;
        Sleep(1000);
	Answer = "Home";
}
Topic archived. No new replies allowed.