8 Replies - 341 Views - Last Post: 16 January 2013 - 12:41 PM Rate Topic: -----

#1 ray1234  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 148
  • Joined: 07-September 12

why doesn't this work?

Posted 16 January 2013 - 12:01 PM

if(10/2 + 1 == 6 || 5)
Is This A Good Question/Topic? 0
  • +

Replies To: why doesn't this work?

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9366
  • View blog
  • Posts: 35,187
  • Joined: 12-June 08

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.
Was This Post Helpful? 0
  • +
  • -

#3 ray1234  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 148
  • Joined: 07-September 12

Re: why doesn't this work?

Posted 16 January 2013 - 12:03 PM

View Postmodi123_1, on 16 January 2013 - 07:02 PM, said:

Come on.. you need to do better than that to explain what "doesn't work" mean.


this expression in the if statement causes an error. why is that?
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9366
  • View blog
  • Posts: 35,187
  • Joined: 12-June 08

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'

Was This Post Helpful? 0
  • +
  • -

#5 ray1234  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 148
  • Joined: 07-September 12

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.
Was This Post Helpful? 0
  • +
  • -

#6 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9366
  • View blog
  • Posts: 35,187
  • Joined: 12-June 08

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
            {
            }

Was This Post Helpful? 1
  • +
  • -

#7 ray1234  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 148
  • Joined: 07-September 12

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
Was This Post Helpful? 0
  • +
  • -

#8 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 9366
  • View blog
  • Posts: 35,187
  • Joined: 12-June 08

Re: why doesn't this work?

Posted 16 January 2013 - 12:14 PM

Ah.. what?
Was This Post Helpful? 0
  • +
  • -

#9 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5571
  • View blog
  • Posts: 11,908
  • Joined: 02-June 10

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)
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1