Thread: kinda stuck.. help please?

  1. #16
    Registered User
    Join Date
    Nov 2008
    Posts
    15
    Quote Originally Posted by Salem View Post
    Now are you using | because you're too lazy to write ||, or is something else going on here?

    | and || are very different animals in C, and casual use of them will just lead you astray.

    if ( a || b ) c = 1;
    Strange, this is where you started.


    > however this latches variable3 to true even when I return variable1 and variable2 to False
    This however is wrong. Something else is going on in your program, which has nothing to do with the if statement.
    If both a and b are FALSE, nothing happens to c
    sorry, I mean ||, i missed the key.

  2. #17
    Registered User
    Join Date
    Nov 2008
    Posts
    15
    this is the problem i'm running into. I want

    a b c
    1 1 1
    1 0 1
    0 1 1
    0 0 0


    but, when a and b are 0, c must be able to be 0 or 1 on it's own, independant of a and b.

    The story goes:

    i turn on either button A or button B and it turn on C. When i turn off button A or B then button C turns off. Now, if I ONLY turn on button C it stays on and I can turn button C off as well.

  3. #18
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I think you need a fourth variable.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #19
    Registered User
    Join Date
    Nov 2008
    Posts
    15
    how would i do that?

  5. #20
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,662
    d = ( !c && ( a || b ) ) || c;

    If c is off, you get a or b
    If c is on, then a and b don't matter.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #21
    Registered User
    Join Date
    Nov 2008
    Posts
    15
    what is the 4th variable?

    cause i've got button A, B, and C...

  7. #22
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by w0nger View Post
    what is the 4th variable?

    cause i've got button A, B, and C...
    d is the "output" of button C - either C itself is set, or A or B is set, so D represents the output stage of C.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  8. #23
    Registered User
    Join Date
    Nov 2008
    Posts
    15
    the output of D is the button C.

    can I just define D as the button C ?

  9. #24
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by w0nger View Post
    the output of D is the button C.

    can I just define D as the button C ?
    Well, I presume you need to know the ACTUAL state of button C as well, right? In which case you need C (the state of the actual button) as well as D (the end result of A, B and C combined).

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  10. #25
    Registered User
    Join Date
    Nov 2008
    Posts
    15
    they would be the same.

    When D is ON then C is ON
    when D is OFF then C is OFF

  11. #26
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by w0nger View Post
    they would be the same.

    When D is ON then C is ON
    when D is OFF then C is OFF
    Yes, but D is ON when A or B is ON too, regardless of C.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  12. #27
    Registered User
    Join Date
    Nov 2008
    Posts
    15
    Quote Originally Posted by matsp View Post
    Yes, but D is ON when A or B is ON too, regardless of C.

    --
    Mats
    Hrmz... no luck. The function of D, which is the same as C, still stays on when A and B go off. ugh.. head hurts.. gonna try this again morrow.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 6
    Last Post: 10-23-2006, 07:22 PM
  2. string array stuck:(
    By mass in forum C Programming
    Replies: 18
    Last Post: 05-22-2006, 04:44 PM
  3. Program stuck in infinite loop-->PLEASE HELP
    By Jedijacob in forum C Programming
    Replies: 5
    Last Post: 03-26-2005, 12:40 PM
  4. Stuck on random generating
    By Vegtro in forum C++ Programming
    Replies: 3
    Last Post: 10-01-2003, 07:37 PM
  5. stuck ky
    By JaWiB in forum Tech Board
    Replies: 2
    Last Post: 06-15-2003, 08:28 PM