# Making the condition shorter

Page 1 of 1

## 3 Replies - 311 Views - Last Post: 23 August 2009 - 05:18 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=121898&amp;s=dafa2fa2083e4f541e8a055dc58cf24b&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 poncho4all

Reputation: 123
• Posts: 1,422
• Joined: 15-July 09

# Making the condition shorter

Posted 23 August 2009 - 04:58 PM

How can i make this condition shorter or in a different way:

```if(cl==1&&(y==300||y==301||y==302||y==303))
```

There has to be another way.
Is This A Good Question/Topic? 0

## Replies To: Making the condition shorter

### #2 OliveOyl3471

• Everybody's crazy but me!

Reputation: 135
• Posts: 6,581
• Joined: 11-July 07

## Re: Making the condition shorter

Posted 23 August 2009 - 05:01 PM

```if(cl==1&&(y>=300 && y<=303))
```

Assuming the numbers are ints (no decimals). But I agree, there has to be another way.

Depending on what you want your code to do, I guess, you could do a while loop and a switch case. Not really less code, but fun anyway.

```int cl=1, y;
while(cl==1){
cout<<"Enter y value: ";
cin>>y;
switch(y){
case 300:
case 301:
case 302:
case 303:cout<<"thank you.\n""Enter 1 to continue or any other number to quit.\n";
cin>>cl;
break;
default: cout<<"Incorrect value, try again."<<endl;
cout<<"enter 1 to continue or any other number to quit.\n";
cin>>cl;
}
}
```

This post has been edited by OliveOyl3471: 23 August 2009 - 05:17 PM

### #3 poncho4all

Reputation: 123
• Posts: 1,422
• Joined: 15-July 09

## Re: Making the condition shorter

Posted 23 August 2009 - 05:05 PM

Wow how did i not saw that, thank you olive i would take this one. Atleast is alot better than what i was doing.

*Need to get away from computer for a sec now*

### #4 OliveOyl3471

• Everybody's crazy but me!

Reputation: 135
• Posts: 6,581
• Joined: 11-July 07

## Re: Making the condition shorter

Posted 23 August 2009 - 05:18 PM

You're welcome. Glad I could help.