How do you make an if statment to several things?

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2008
Posts: 1
Reputation: mercedesbenz is an unknown quantity at this point 
Solved Threads: 0
mercedesbenz mercedesbenz is offline Offline
Newbie Poster

How do you make an if statment to several things?

 
0
  #1
Oct 29th, 2008
I'm making a program and want to use an if statement to add a 0 to output if the numbers = 0-9. I know how to do an if statement like:

int number=0;
if (number==5){
cout << " whatever " << endl;
}
Is there any way to do somthing like this?

int number=0;
if (number==1-9){
cout << " whatever " endl;
Thankyou for the help, it is well apreciated!
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 1,739
Reputation: Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all 
Solved Threads: 281
Lerner Lerner is online now Online
Posting Virtuoso

Re: How do you make an if statment to several things?

 
0
  #2
Oct 29th, 2008
Use a compound conditional like this:

if(number >0 && number < 10)
Klatu Barada Nikto
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 390
Reputation: skatamatic will become famous soon enough skatamatic will become famous soon enough 
Solved Threads: 39
skatamatic skatamatic is offline Offline
Posting Whiz

Re: How do you make an if statment to several things?

 
0
  #3
Oct 30th, 2008
Logical AND - &&, Logical OR - ||, Logical Inversion - !

Some things you should get comfortable with.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC