473,395 Members | 1,815 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Using the OR operator with integers?

I'm attempting to code a soundboard, however, due to the policies of who I am coding for, I need to create a profanity filter, currently, what I am trying to do, is create a statement that takes the currently selected index, and if it matches one of the marked profane containing indexes, it will not be played, and display a message explaining why.
However, I get this error:
Operator '||' cannot be applied to operands of type 'bool' and 'int'.
I've tried using the bitwise OR ( | ) and I get:
Operator '|' cannot be applied to operands of type 'bool' and 'int'.
Any help?
Here is the code if it helps.
Expand|Select|Wrap|Line Numbers
  1. int index = listBoxCrazyEights.SelectedIndex;
  2. if (index == 6 || 8 || 9)
  3. {
  4. //Code here if this is true
  5. }
Mar 31 '11 #1

✓ answered by GaryTexmo

You need to say what you're comparing against each time.

Expand|Select|Wrap|Line Numbers
  1. if (index == 6 || index == 8 || index == 9) ...
What you have there is trying to compare index against the result of (6 || 8 || 9) and since integers aren't booleans (well, not anymore :P) you get the error.

2 1226
GaryTexmo
1,501 Expert 1GB
You need to say what you're comparing against each time.

Expand|Select|Wrap|Line Numbers
  1. if (index == 6 || index == 8 || index == 9) ...
What you have there is trying to compare index against the result of (6 || 8 || 9) and since integers aren't booleans (well, not anymore :P) you get the error.
Mar 31 '11 #2
Plater
7,872 Expert 4TB
If you had a collection such as List<int> you could just state if its contained in it or not.
Example:

Expand|Select|Wrap|Line Numbers
  1. List<int> ProfaneIndexes = new List<int>();
  2. ProfaneIndexes.Add(6);
  3. ProfaneIndexes.Add(8);
  4. ProfaneIndexes.Add(9);
  5. int CurrentIndex = listBoxCrazyEights.SelectedIndex;
  6. if (ProfaneIndexes.Contains(CurrentIndex))
  7. {//index is in the "Profane" category
  8. }
  9.  
  10. When your list of profane indexes gets large, this will become much more helpful. 
  11.  
Apr 7 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: Jeff Melvaine | last post by:
I note that I can write expressions like "1 << 100" and the result is stored as a long integer, which means it is stored as an integer of arbitrary length. I may need to use a large number of...
5
by: Roger Leigh | last post by:
I've written a simple container template class to contain a single value. This emits a signal when the value is changed (it's used as a notifier of changes), and listeners can connect to its...
2
by: Tony Johansson | last post by:
Hello Experts! I have one class template here called Handle and one concrete class called Point. At the bottom is the main program and the class template definitions for Handle. This program...
0
by: Robert Potthast | last post by:
Hello, I want to make my garbage collector more safe. To make it more safe I need to know if an object has been allocated on the stack or on the heap using the operator new. My garbage collector...
3
by: Adam Monsen | last post by:
The following code uses the % operator to print possibly unitialized data attributes: ------------------------8<------------------------ class J: name = '' value = '' def __str__(self): vals =...
24
by: Bangalore | last post by:
Hi all, I have a problem in accessing elements using overloaded operator . Consider, const int SIZE=10; int FALSE=0; class Array { private: int x; public:
17
by: Martin | last post by:
Below is some sample code to illustrate two warnings I get using a Hitachi compiler. When I use the GCC compiler I get a clean compile. I'd be grateful if someone could explain what the warnings...
2
by: Bharath | last post by:
Hello All, Can you please let me know if we can do pointer arthrmetic using operator overloading? If not, can you please explain why it's not supported by compiler? I tried below e.g. which was...
5
by: jewel87 | last post by:
Hello, I am working on a program which uses a dynamic array of Employee class objects, the array is defined in EmployeeList class. When i am calling a function from my form to enter or display...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.