943,502 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 36512
  • C++ RSS
Jun 9th, 2004
1

switch/case statement

Expand Post »
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;
        }
Similar Threads
Reputation Points: 12
Solved Threads: 1
Newbie Poster
kalachylde is offline Offline
9 posts
since Jun 2004
Jun 9th, 2004
0

Re: switch/case statement

well, nevermind... I'll just do the nested thing... I didn't think about that (or better yet didn't think at all).
Reputation Points: 12
Solved Threads: 1
Newbie Poster
kalachylde is offline Offline
9 posts
since Jun 2004
Jun 11th, 2004
0

Re: switch/case statement

use if, if else and else.You can have multiple checks in a if statement

C++ Syntax (Toggle Plain Text)
  1. if(condition == true || condition < high)
  2.  
  3. if(condition == true && condition < high)
Reputation Points: 108
Solved Threads: 7
Posting Whiz in Training
FireNet is offline Offline
256 posts
since May 2004
Jun 11th, 2004
0

Re: switch/case statement

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
Team Colleague
Reputation Points: 121
Solved Threads: 57
Posting Virtuoso
kc0arf is offline Offline
1,629 posts
since Mar 2004
Jun 11th, 2004
0

Re: switch/case statement

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
Reputation Points: 45
Solved Threads: 0
Light Poster
Bleek is offline Offline
28 posts
since Mar 2004
Jun 11th, 2004
0

Re: switch/case statement

Nested switch case statements work with no problems... thanks guys
Reputation Points: 12
Solved Threads: 1
Newbie Poster
kalachylde is offline Offline
9 posts
since Jun 2004
Jun 12th, 2004
0

Re: switch/case statement

To Kc0arf,
Not necessary I belive.Especially when only two conditions are being compared or multiple non dependants

C++ Syntax (Toggle Plain Text)
  1. if(condirion1 || condirion2 || condirion3)

it will be needed if you are going in for dependants

C++ Syntax (Toggle Plain Text)
  1. if(condirion1 || (condirion2 && condirion3) || condition4)

To Bleek,
What you say is very true.:-)
Reputation Points: 108
Solved Threads: 7
Posting Whiz in Training
FireNet is offline Offline
256 posts
since May 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: practice(newbie)
Next Thread in C++ Forum Timeline: Advantages of C++ SAFEARRAY: Explain





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC