# Testing Multiple Conditions

Show 80 post(s) from this thread on one page
Page 1 of 2 12 Last
• 10-20-2002
awilmut
Testing Multiple Conditions
Searched, couldn't find it.. I'm looking to simplify this:

Can anyone help?

Andrew
• 10-20-2002
Sang-drax
If it's continuous:
• 10-20-2002
awilmut
it's not :D but thanks. Anyone else?
• 10-20-2002
awilmut
oops.. sorry folks, it should be:

• 10-20-2002
endo
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
• 10-20-2002
Sebastiani
Code:

``` bool  is_true(char ch) {     switch(tolower(ch)) {   case 'a': case 'x': case 'b' : case 't':   return true;   }   return false;  }```
• 10-20-2002
awilmut
Thanks Guys...
• 10-20-2002
Captain Penguin
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)))```
• 10-20-2002
BMJ
.... perhaps you should implement it differently then :)
• 10-20-2002
Captain Penguin
Quote:

Originally posted by BMJ
.... perhaps you should implement it differently then :)
hey, for my simple chess program it works. What would you suggest? :)
• 10-20-2002
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
• 10-20-2002
Captain Penguin
Quote:

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.
• 10-20-2002
moi
Quote:

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
• 10-20-2002
Captain Penguin
Quote:

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". :)
• 10-20-2002
Sebastiani
Arrays come to mind...
Show 80 post(s) from this thread on one page
Page 1 of 2 12 Last