Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > if

Reply
 
 
ahso
Guest
Posts: n/a
 
      02-02-2012
Hi
I only want either first or second if but not both executed. ie. if
value 1 do not execute 2 even if 2nd value ==1 but also if 2nd do not
execute first if.
Thanks


if (R22value == 1){
DreiDimensional = 0;
function();
}

if (R23value == 1){
DreiDimensional = 1;
function();
}
 
Reply With Quote
 
 
 
 
Ian Collins
Guest
Posts: n/a
 
      02-02-2012
On 02/ 2/12 11:13 PM, ahso wrote:
> Hi
> I only want either first or second if but not both executed. ie. if
> value 1 do not execute 2 even if 2nd value ==1 but also if 2nd do not
> execute first if.


That requirement contradicts its self.

--
Ian Collins
 
Reply With Quote
 
 
 
 
Fred Zwarts \(KVI\)
Guest
Posts: n/a
 
      02-02-2012
"ahso" wrote in message
news:(E-Mail Removed)...
>
>Hi
>I only want either first or second if but not both executed. ie. if
>value 1 do not execute 2 even if 2nd value ==1 but also if 2nd do not
>execute first if.
>Thanks
>
>
>if (R22value == 1){
> DreiDimensional = 0;
> function();
>}
>
>if (R23value == 1){
> DreiDimensional = 1;
> function();
>}


It is not clear to me what you mean. As I read it, the obvious solution is:

if (R22value == 1){
DreiDimensional = 0;
function();

} else if (R23value == 1){
DreiDimensional = 1;
function();
}

 
Reply With Quote
 
ahso
Guest
Posts: n/a
 
      02-02-2012
The problem is that either value can be 1. I only want to avoid
running both simultanoulsy. I tried with setting within each if the
other value to 0 but
that's not working. I probably need to do as Fred so users have to
click the first value to disable then click the second.
 
Reply With Quote
 
Fred Zwarts \(KVI\)
Guest
Posts: n/a
 
      02-02-2012
"ahso" wrote in message
news:(E-Mail Removed)...
>
>The problem is that either value can be 1. I only want to avoid
>running both simultanoulsy. I tried with setting within each if the
>other value to 0 but
>that's not working. I probably need to do as Fred so users have to
>click the first value to disable then click the second.


What are types of R22value, R23value and DrieDimensional?
You use them as integer-like variables, what are their expected values?
You seem to use only the values 0 and 1, maybe you should use bool type.
It is still not clear to me what you want to do.
Maybe you could explicitly program the four cases,
which would make your intention more clear.
What do you want to do in the other two cases?

if (R22value == 1 ){
if (R23value == 1){
// R22value == 1, R23value == 1

throw Inconsistency;????
ComplainToUser ();?????

} else {
// R22value == 1, R23value != 1

DreiDimensional = 0;
function();

}
} else {
if (R23value == 1){
// R22value != 1, R23value == 1

DreiDimensional = 1;
function();

} else {
// R22value != 1, R23value != 1

throw Inconsistency;???????
ComplainToUser ();?????

}
}


 
Reply With Quote
 
copx
Guest
Posts: n/a
 
      02-02-2012
On 02.02.2012 11:13, ahso wrote:
> Hi
> I only want either first or second if but not both executed. ie. if
> value 1 do not execute 2 even if 2nd value ==1 but also if 2nd do not
> execute first if.
> Thanks
>
>
> if (R22value == 1){
> DreiDimensional = 0;
> function();
> }
>
> if (R23value == 1){
> DreiDimensional = 1;
> function();
> }


English is not your first language, right? Seriously, your broken
English makes it hard to understand what you actually mean.
I guess you want this:

if (R23value != 1 && R22value == 1){
DreiDimensional = 0;
function();
}

if (R22value != 1 && R23value == 1){
DreiDimensional = 1;
function();
}



 
Reply With Quote
 
Juha Nieminen
Guest
Posts: n/a
 
      02-02-2012
ahso <(E-Mail Removed)> wrote:
> Hi
> I only want either first or second if but not both executed. ie. if
> value 1 do not execute 2 even if 2nd value ==1 but also if 2nd do not
> execute first if.
> Thanks
>
>
> if (R22value == 1){
> DreiDimensional = 0;
> function();
> }
>
> if (R23value == 1){
> DreiDimensional = 1;
> function();
> }


Just put an "else" before the second "if".
 
Reply With Quote
 
LR
Guest
Posts: n/a
 
      02-02-2012
ahso wrote:
> Hi
> I only want either first or second if but not both executed. ie. if
> value 1 do not execute 2 even if 2nd value ==1 but also if 2nd do not
> execute first if.
> Thanks
>
>
> if (R22value == 1){
> DreiDimensional = 0;
> function();
> }
>
> if (R23value == 1){
> DreiDimensional = 1;
> function();
> }



What you want to do isn't entirely clear to me, but perhaps this snippet
will be of use, if only as a point of departure,


void f2(const int R22value, const int R23value) {

std::cout << "(" << R22value << "," << R23value << ") ";

static const int threeDim = 1;
static const int twoDim = 0;
static const int invalidDim = -1;

const bool r2 = R22value != 0;
const bool r3 = R23value != 0;

const std:air<bool,bool> ab(r2,r3);


const int dim =
ab == std::make_pair(false,true) ? threeDim :
ab == std::make_pair(true,false) ? twoDim :
invalidDim;


if(dim != invalidDim) {
// call function here
std::cout << "It\'s valid, it was " << dim << std::endl;
}
else {
// don't call function here
std::cout << "It was invalid" << std::endl;
}

}
 
Reply With Quote
 
ahso
Guest
Posts: n/a
 
      02-03-2012
Thanks copx. I added after your code (only boolean 0/1 values):

if (R23value == 1 && R22value == 1){
R22value = 0;
R23value = 0;

}

That way users have to double click but ok.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments