• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 242
  • Last Modified:

operator question

here is the code:

if ((sFileExtension != ".doc") || (sFileExtension != ".txt"))
{

}

im looking to see if uploaded file is either .doc OR .txt


the above doesnt work. how come?

0
tmueller18
Asked:
tmueller18
  • 4
1 Solution
 
millsoftCommented:
Hi tmueller18,

Your boolean operators are wrong.

if ((sFileExtension == ".doc") || (sFileExtension == ".txt"))
{
    // extension is .DOC or .TXT
}
else
{
    // it is not
}

Cheers!
Brad
0
 
millsoftCommented:
!= is "NOT EQUALS"
== is "EQUALS"

You were checking to see if the extension is "NOT .DOC or NOT .TXT".  One of those conditions will ALWAYS be true.
0
 
millsoftCommented:
>One of those conditions will ALWAYS be true.

because it cannot be both at the same time.
0
 
tmueller18Author Commented:
thanks!
0
 
millsoftCommented:
happy to help
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now