if(10/2 + 1 == 6 || 5)
why doesn't this work?
Page 1 of 18 Replies - 140 Views - Last Post: 16 January 2013 - 12:41 PM
Replies To: why doesn't this work?
#2
Re: why doesn't this work?
Posted 16 January 2013 - 12:02 PM
Come on.. you need to do better than that to explain what "doesn't work" mean.
#3
Re: why doesn't this work?
Posted 16 January 2013 - 12:03 PM
#4
Re: why doesn't this work?
Posted 16 January 2013 - 12:04 PM
Though.. depending on how you roll it - the error message is pretty darn explanatory.
Quote
Operator '||' cannot be applied to operands of type 'bool' and 'int'
Operator '||' cannot be applied to operands of type 'int' and 'int'
Operator '||' cannot be applied to operands of type 'int' and 'int'
#5
Re: why doesn't this work?
Posted 16 January 2013 - 12:08 PM
thanks that was helpful...
i know that. i mean i want to compare a number with either number a or number b
how would you go about writing it.
i know that. i mean i want to compare a number with either number a or number b
how would you go about writing it.
#6
Re: why doesn't this work?
Posted 16 January 2013 - 12:13 PM
Use a variable.
int foo = 10 / 2 + 1;
if ( (foo == 6) || (foo == 5))
{
}
else
{
}
#7
Re: why doesn't this work?
Posted 16 January 2013 - 12:14 PM
or better yet,
best out of 5.
what algorithm i would use to find out the first to number
i.e. so best of 5 would mean first to 3.
"" "" "" 10 would mean first to 6
"" "" "" 15 would mean first to 8
etc
best out of 5.
what algorithm i would use to find out the first to number
i.e. so best of 5 would mean first to 3.
"" "" "" 10 would mean first to 6
"" "" "" 15 would mean first to 8
etc
#9
Re: why doesn't this work?
Posted 16 January 2013 - 12:41 PM
Quote
if(10/2 + 1 == 6 || 5)
if ... or 5
That's what you wrote.. if something or 5. Or 5 what?
You can't expect the computer to just infer that you want to compare your formula to 6 or 5. There is no infering by context in programming. The computer does exactly what you tell it to. It is not artificially intelligent enough to read the intent of your statement and translate that to a working line of code.
Quote
Operator '||' cannot be applied to operands of type 'bool' and 'int'
Right... or 5 is not a valid comparrison to a bool which is only true or false. You have to make a statement that provides a true or false result.
Did you really mean?
"If my formula is equal to 6 or my formula is equal to 5"
if (((*10/2) + 1) == 6 || ((*10/2) + 1) == 5)
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote








|