CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2012
    Posts
    4

    Need help with a logic error please.

    while ((answer != 'A') || (answer != 'B') || (answer != 'C') || (answer != 'D'))

    This section of code accepts no answer, instead of just A B C or D.

    Any thoughts on how I should do this?

    Thanks/

  2. #2
    GCDEF is offline Elite Member Power Poster GCDEF has a reputation beyond repute (3000+) GCDEF has a reputation beyond repute (3000+) GCDEF has a reputation beyond repute (3000+) GCDEF has a reputation beyond repute (3000+) GCDEF has a reputation beyond repute (3000+) GCDEF has a reputation beyond repute (3000+) GCDEF has a reputation beyond repute (3000+) GCDEF has a reputation beyond repute (3000+) GCDEF has a reputation beyond repute (3000+) GCDEF has a reputation beyond repute (3000+) GCDEF has a reputation beyond repute (3000+)
    Join Date
    Nov 2003
    Posts
    11,568

    Re: Need help with a logic error please.

    Think about it a bit. Since you're using logical or ||, if any of those conditions is true, the expression is true.

    Say answer is 'A'. If it's 'A', it's not 'B', so the expression is true. So instead of any of those conditions being true, you want all of them to be true. Think about what you may need to change to accomplish that.

  3. #3
    Join Date
    Nov 2012
    Posts
    4

    Re: Need help with a logic error please.

    Got it working, thanks!

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts



HTML5 Development Center

Click Here to Expand Forum to Full Width