switch/case statement

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

Join Date: Jun 2004
Posts: 9
Reputation: kalachylde is an unknown quantity at this point 
Solved Threads: 1
kalachylde's Avatar
kalachylde kalachylde is offline Offline
Newbie Poster

switch/case statement

 
1
  #1
Jun 9th, 2004
Hi all,
Someone is going to laugh at me for this one.
Can you have two arguments in a switch case statement?
switch (choiceA, choiceB)
	{
	case 1,2:
               cout <<"Information";
               break;
        default:
               break;
        }
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 9
Reputation: kalachylde is an unknown quantity at this point 
Solved Threads: 1
kalachylde's Avatar
kalachylde kalachylde is offline Offline
Newbie Poster

Re: switch/case statement

 
0
  #2
Jun 9th, 2004
well, nevermind... I'll just do the nested thing... I didn't think about that (or better yet didn't think at all).
Reply With Quote Quick reply to this message  
Join Date: May 2004
Posts: 256
Reputation: FireNet will become famous soon enough FireNet will become famous soon enough 
Solved Threads: 6
FireNet's Avatar
FireNet FireNet is offline Offline
Posting Whiz in Training

Re: switch/case statement

 
0
  #3
Jun 11th, 2004
use if, if else and else.You can have multiple checks in a if statement

  1. if(condition == true || condition < high)
  2.  
  3. if(condition == true && condition < high)
See what you can, remember what you need

Fourzon | Earn via Coding
Reply With Quote Quick reply to this message  
Join Date: Mar 2004
Posts: 1,620
Reputation: kc0arf is a jewel in the rough kc0arf is a jewel in the rough kc0arf is a jewel in the rough 
Solved Threads: 51
Team Colleague
kc0arf kc0arf is offline Offline
Posting Virtuoso

Re: switch/case statement

 
0
  #4
Jun 11th, 2004
Hello,

FireNet, you need to use more () in those statements, as you will want to be clear on the operator precidence. I do not have my books handy, but am concerned that the == (equals) operator will be evaluated after the || (or). I would use () to make sure that the statements execute the way you want them to.

if ( (condition == true) || (condition < high) )

Christian
Reply With Quote Quick reply to this message  
Join Date: Mar 2004
Posts: 28
Reputation: Bleek is an unknown quantity at this point 
Solved Threads: 0
Bleek Bleek is offline Offline
Light Poster

Re: switch/case statement

 
0
  #5
Jun 11th, 2004
actually, if i was paying attention in class, i believe it's the other way around. logical operators such as || (or) && (and) etc. come before mathamatical operators, <= (less than or equal to) != (not equal to) etc. I'm sure that will compile just fine without it. but this is a good lesson to people with algorithms because in C++ certain things are evaluated first... it will give you headaches later on...
peace
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 9
Reputation: kalachylde is an unknown quantity at this point 
Solved Threads: 1
kalachylde's Avatar
kalachylde kalachylde is offline Offline
Newbie Poster

Re: switch/case statement

 
0
  #6
Jun 11th, 2004
Nested switch case statements work with no problems... thanks guys
Reply With Quote Quick reply to this message  
Join Date: May 2004
Posts: 256
Reputation: FireNet will become famous soon enough FireNet will become famous soon enough 
Solved Threads: 6
FireNet's Avatar
FireNet FireNet is offline Offline
Posting Whiz in Training

Re: switch/case statement

 
0
  #7
Jun 12th, 2004
To Kc0arf,
Not necessary I belive.Especially when only two conditions are being compared or multiple non dependants

  1. if(condirion1 || condirion2 || condirion3)

it will be needed if you are going in for dependants

  1. if(condirion1 || (condirion2 && condirion3) || condition4)

To Bleek,
What you say is very true.:-)
See what you can, remember what you need

Fourzon | Earn via Coding
Reply With Quote Quick reply to this message  
Reply

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




Views: 23341 | Replies: 6
Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC