If And Else Not Working Right

Hello i am still kinda new to c++, and i have been getting mad at this, for some reason my code will not work if and else.

When i open the program and type something not in the if statement it still executes whats in the if statement, can someone please help

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
 void Input() {
	 string input;
	 cin >> input;
	 cout << "\n";

	 if (input == "cmds" || "CMDS") {
		  cout << Commands << endl << "\r";
		  Input();

	 }

	 else {
		  exit(0);
	 }
}
Last edited on
Line 6 looks wrong to me.

Try...
if (input == "cmds" || input == "CMDS") {
Thanks
Why:
c++ is explict, and c++ logic states that zero is false, anything else is true.
your original logic breaks down to...

if (input == "cmds) or
("CMDS" != 0)

"CMDS" does not == 0. Therefore it is true.

with the root cause of not being explicit (you didn't ask for input == "CMDS", you gave a human readable but compiler confusing and unfortunately legal totally different condition).
Topic archived. No new replies allowed.