Searched, couldn't find it.. I'm looking to simplify this:
if ((menuSelection != 'A') || (menuSelection != 'B') || (menuSelection != 'C') || (menuSelection != 'D') || (menuSelection != 'X'))
Can anyone help?
Thanks in advance..
Andrew
Searched, couldn't find it.. I'm looking to simplify this:
if ((menuSelection != 'A') || (menuSelection != 'B') || (menuSelection != 'C') || (menuSelection != 'D') || (menuSelection != 'X'))
Can anyone help?
Thanks in advance..
Andrew
If it's continuous:
if (menuSelection >= 'A' && menuSelection <= 'X')
Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling
it's notbut thanks. Anyone else?
oops.. sorry folks, it should be:
if ((menuSelection != 'A') && (menuSelection != 'B') && (menuSelection != 'C') && (menuSelection != 'D') && (menuSelection != 'X'))
you could put it into a small function:
this kind of function is good if you are using the same menu more than once and need to frequently validate the inputCode:bool checkInput( const char& input ) { //perform if statement to make sure a valid character is entered. return true; }
Couldn't think of anything interesting, cool or funny - sorry.
Code:bool is_true(char ch) { switch(tolower(ch)) { case 'a': case 'x': case 'b' : case 't': return true; } return false; }
Code:#include <cmath> #include <complex> bool euler_flip(bool value) { return std::pow ( std::complex<float>(std::exp(1.0)), std::complex<float>(0, 1) * std::complex<float>(std::atan(1.0) *(1 << (value + 2))) ).real() < 0; }
Thanks Guys...
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)))
.... perhaps you should implement it differently then![]()
hey, for my simple chess program it works. What would you suggest?Originally posted by BMJ
.... perhaps you should implement it differently then![]()
![]()
use a case statement, have switches for 'A' 'B' 'C' 'D' and 'X', and have the code under the
if ((menuSelection != 'A') || (menuSelection != 'B') || (menuSelection != 'C') || (menuSelection != 'D') || (menuSelection != 'X'))
be exectued in the default: thingy instead
hello, internet!
Thats diferent than a compound if statement, though. What you've just proposed is a replacement for multiple if statements.Originally posted by moi
use a case statement, have switches for 'A' 'B' 'C' 'D' and 'X', and have the code under the
if ((menuSelection != 'A') || (menuSelection != 'B') || (menuSelection != 'C') || (menuSelection != 'D') || (menuSelection != 'X'))
be exectued in the default: thingy instead
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 entriesOriginally posted by Captain Penguin
Thats diferent than a compound if statement, though. What you've just proposed is a replacement for multiple if statements.
hello, internet!
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".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![]()
Arrays come to mind...
Code:#include <cmath> #include <complex> bool euler_flip(bool value) { return std::pow ( std::complex<float>(std::exp(1.0)), std::complex<float>(0, 1) * std::complex<float>(std::atan(1.0) *(1 << (value + 2))) ).real() < 0; }