1. compare question

Hey all, is it possible to use an if statement or strcmp to compare more than one thing?
IE
I want to compare a variable (count) to 5, 10, 15, 20, 25, 30, 35, 40, --> 100
and pause if the variable is equal to any one of them.
something like this
Code:
```void displayall()
{
int i;
int count=0;
system("cls");
for (i=0; i<99; i++)
{
if (!strcmp ((entry[i].name), "*"))
{
}
else
{
count++;
cout << (entry[i].name) << "\n" << flush;
cout << (entry[i].street) << "\n" << flush;
cout << (entry[i].streetii) << "\n" << flush;
cout << (entry[i].postcode) << "\n\n" << flush;
if (count==5,10,15,20,25) // <------ can you do something like this?? obviously this wont work but you get the picture.
{
system("pause");
}
}
}
}//end function```
or perhaps use strcmp ??? if so how would you format the statement?
any help greatly appreciated. I am using VC++ 6.
thanks
DigiAcid

2. Well, there are probably several ways to accomplish such, though none nearly as convenient as what you're trying to do.

By the way, you don't even need such a method for what you're trying to do... as you can use the modulus operator.

Code:
`if(count % 5 == 0)`
No matter, here are some ways of doing such:

*) A switch statement:

Code:
```switch(count) {
case 5: case 10: case 15: case 20:
case 25: ....
// Do something
}```
*) Use std::set<T> or std::map<T, bool>
Code:
```std::set<int> set_of_ints;
set_of_ints.insert(5);
set_of_ints.insert(10);
...
set_of_ints.insert(95);

if(set_of_ints.find(count) != set_of_ints.end()) {
// Do something
}```
The nice thing about this method is that it can work with any data type with reasonable effort (unlike the switch).

You could also implement the same idea with an array, or even a std::bitset, if your data type is only an integer.

3. thanks for your reply m8 I must say I dont really understand the code youve put at the bottom as my lecturer is teaching us an arcaic form of c++ , and I can't understand anything he says (hes iranian with little grasp of the english language), and namespace std is lost on me

if(count % 5 ==0) ??

could you explain in longer terms what this means as I need to understand everything in my code when asked.

I get this much: if ( conditions in here are true then do whats in the brackets below)

is it if count is devisable by 5 then do whats in the brackets???

thanks for your help its much appreciated

4. Originally Posted by DigiAcid
if(count % 5 ==0) ??

could you explain in longer terms what this means as I need to understand everything in my code when asked.
% is the modulus operator. It gives one the remainder of the division of the two operands. So 5 divides 5 with a remainder of 0, as it does 10, 15, 20, and so on.

is it if count is devisable by 5 then do whats in the brackets???
Exactly. In the brackets would be the code to execute if count is a multiple of 5.

5. Ah excellent thanks very much for your help it is greatly appreciated