Thread: whats wrong with this if clause

  1. #1
    Registered User
    Join Date
    Apr 2019
    Posts
    808

    whats wrong with this if clause

    i have the following if statement
    Code:
    if (((temp_x - 2 >= 0 || temp_x - 2 <= 7) && (temp_y + 2 * multiplyer_y >= 0 || temp_y + 2 * multiplyer_y <=7)) &&
                ((temp_x + 2 >= 0 || temp_x + 2 <= 7) && (temp_y + 2 * multiplyer_y >= 0 || temp_y + 2 * multiplyer_y <=7)))
            {
                //record branch
                route[route_count][move][0] = 2;
                move += 1;
                //jump left
                route[route_count][move][0] = 0;
                temp_x -= 2;
                temp_y += 2 * multiplyer_y;
                move += 1;
            }
    for some reason it is always true on debug temp_x got upto 32
    coop

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    So what are the values of the variables, temp_x, temp_y, and multiplyer_y?

    What order do you think the following will be interpreted: temp_y + 2 * multiplyer_y?

  3. #3
    Registered User
    Join Date
    Feb 2019
    Posts
    1,078
    Quote Originally Posted by jimblumberg View Post
    So what are the values of the variables, temp_x, temp_y, and multiplyer_y?

    What order do you think the following will be interpreted: temp_y + 2 * multiplyer_y?
    Doesn't matter, the entire expression is always true.

  4. #4
    Registered User
    Join Date
    Apr 2019
    Posts
    808
    multiplyer_y is either 1 or -1 in this particular scenario it is 1
    temp_x and temp_y should be between 0 and 7
    temp_y + 2 * multiplyer_y should evaluate to either :
    temp_y + 2 * -1 = temp_y -2 or
    temp_y + 2 * 1= temp_y +2

  5. #5
    Registered User
    Join Date
    Apr 2019
    Posts
    808
    i see my mistake i have || instead of && between the limits so im saying if temp is >= 0 equates true.... doesnt matter if temp_x is 0 or 500 billion where as i want to limit the values from 0 to 7

    I have been staring at it for an hour as well duh!!!!
    Last edited by cooper1200; 05-09-2019 at 12:31 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. whats wrong?
    By samuelanonymous in forum C Programming
    Replies: 5
    Last Post: 10-17-2007, 04:50 PM
  2. whats wrong with this? no errors but wrong result
    By InvariantLoop in forum C Programming
    Replies: 6
    Last Post: 01-28-2005, 12:48 AM
  3. Whats wrong ??
    By winsonlee in forum C Programming
    Replies: 2
    Last Post: 04-24-2004, 06:18 AM
  4. can anyone tell me whats wrong
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 07-30-2002, 07:23 AM
  5. whats wrong??
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 05-24-2002, 08:30 PM

Tags for this Thread