I'm teaching myself C++ and I've decided to make a game of Rock-Paper-Scissors. I'm at the beginning part where it checks if the user entered in rock, paper, or scissors. If the user enters in something else it should say "Invalid input." This is what I've come up with so far:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
string user_input = "";
while (user_input == "")
{
cout << "Please type in: Rock, Paper, or Scissors" << "\n";
cin >> user_input;
if (user_input != "rock" || user_input != "paper" || user_input != "scissors")
{
user_input = "";
}
else
{
cout << "Invalid input." << "\n";
}
}
If I type in, say... paper, what winds up happening is it just outputs "Please type in: Rock, Paper, or Scissors" repeatedly, but whenever I set up a breakpoint on the conditional statement it has user_input as "paper". So I'm unsure as to why the conditional statement isn't executing it as desired.
Say the user types "rock". user_input != "rock" will be false user_input != "paper" will be true.
No matter what is typed the whole condition will always be true
Ahh, thank you. And I noticed that I should move the Invalid input to the same part as the user_input = "" and just remove the else statement all together.
@Mats, yeah I changed the output to lowercase rock, paper, scissors and if you notice in the post above yours I removed the else statement and added the invalid input to where I set user_input to an empty string.