# Testing Multiple Conditions

This is a discussion on Testing Multiple Conditions within the C++ Programming forums, part of the General Programming Boards category; Searched, couldn't find it.. I'm looking to simplify this: if ((menuSelection != 'A') || (menuSelection != 'B') || (menuSelection != ...

1. ## Testing Multiple Conditions

Searched, couldn't find it.. I'm looking to simplify this:

Can anyone help?

Andrew

2. If it's continuous:

3. it's not but thanks. Anyone else?

4. oops.. sorry folks, it should be:

5. you could put it into a small function:
Code:
```bool checkInput( const char& input )
{
//perform if statement to make sure a valid character is entered.
return true;
}```
this kind of function is good if you are using the same menu more than once and need to frequently validate the input

6. Code:
```bool
is_true(char ch) {

switch(tolower(ch)) {

case 'a': case 'x': case 'b' : case 't':
return true;

}

return false;
}```

7. Thanks Guys...

8. Here's a doozy of a compound boolean statement (its movement checking for a knight in my chess game):

Code:
```if((x2 == (x1 - 2) && y2 == (y1 -1)) || (x2 == (x1 - 2) && y2 == (y1 + 1)) ||
(x2 == (x1 -1) && y2 == (y1-2)) || (x2 == (x1 - 1) && y2 == (y1 + 2)) ||
(x2 == (x1 + 1) && y2 == (y1 -2)) || (x2 == (x1 + 1) && y2 == (y1 + 2)) ||
(x2 == (x1 + 2) && y2 == (y1 - 1)) || (x2 == (x1 + 2) && y2 == (y1 + 1)))```

9. .... perhaps you should implement it differently then

10. Originally posted by BMJ
.... perhaps you should implement it differently then
hey, for my simple chess program it works. What would you suggest?

11. use a case statement, have switches for 'A' 'B' 'C' 'D' and 'X', and have the code under the

be exectued in the default: thingy instead

12. Originally posted by moi
use a case statement, have switches for 'A' 'B' 'C' 'D' and 'X', and have the code under the

be exectued in the default: thingy instead
Thats diferent than a compound if statement, though. What you've just proposed is a replacement for multiple if statements.

13. Originally posted by Captain Penguin
Thats diferent than a compound if statement, though. What you've just proposed is a replacement for multiple if statements.
i made the assumption (wrongly i guess) that he would want to be processing entry for the valid keys at the same time that he elimiates bad entries

14. Originally posted by moi
i made the assumption (wrongly i guess) that he would want to be processing entry for the valid keys at the same time that he elimiates bad entries
Hey whaddya know, that IS what he was doing. I sort of ignored his main post and concentrated on the phrase of the subject, "Testing multiple conditions".

15. Arrays come to mind...

Page 1 of 2 12 Last