Check string with possible inputs?

I need to check an input with 2 possible values, then have that lead to another function based on what was chosen.

But for now I just want to check for correct inputs.

But for some reason this isn't working as expected.. Everything is turning up as an error, and it won't loop and shows end of code, and never thanks!.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
int main ()
{

	bool i = 0;
	while (!i){
		cout << "What do you have? (Cat/Dog)\n" ;
	string huh;
			getline(cin, huh, '\n');

			if (!(huh =="Cat") || !(huh == "cat") || !(huh =="Dog") || !(huh == "dog"))
				cout << "Error: Please enter Cat or Dog\n";

			else 
				cout << "Thanks!\n";
				i = 1;
	}
  return 0;
}
Last edited on
Let's say you have entered "Cat"
Your condition:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
!(huh =="Cat") || !(huh == "cat") || !(huh =="Dog") || !(huh == "dog")
      ↑True
↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
!true || !(huh == "cat") || !(huh =="Dog") || !(huh == "dog")
  ↑false
↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
false || !(huh == "cat") || !(huh =="Dog") || !(huh == "dog")
                ↑false
↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
false || !false || !(huh =="Dog") || !(huh == "dog")
              ↑true
↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
false || true || !(huh =="Dog") || !(huh == "dog")
       ↑true
↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
true ||  !(huh =="Dog") || !(huh == "dog")
       ↑true
↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
true || !(huh == "dog")true
It is actually always be true!
Either get rid of negation and swap than/else or change or to and
Last edited on
Topic archived. No new replies allowed.