954,124 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

switch/case statement

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;
        }
kalachylde
Newbie Poster
9 posts since Jun 2004
Reputation Points: 12
Solved Threads: 1
 

well, nevermind... I'll just do the nested thing... I didn't think about that (or better yet didn't think at all).

kalachylde
Newbie Poster
9 posts since Jun 2004
Reputation Points: 12
Solved Threads: 1
 

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

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

if(condition == true && condition < high)
FireNet
Posting Whiz in Training
258 posts since May 2004
Reputation Points: 108
Solved Threads: 7
 

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

kc0arf
Posting Virtuoso
Team Colleague
1,937 posts since Mar 2004
Reputation Points: 121
Solved Threads: 57
 

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

Bleek
Light Poster
28 posts since Mar 2004
Reputation Points: 45
Solved Threads: 0
 

Nested switch case statements work with no problems... thanks guys

kalachylde
Newbie Poster
9 posts since Jun 2004
Reputation Points: 12
Solved Threads: 1
 

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

if(condirion1 || condirion2 || condirion3)


it will be needed if you are going in for dependants

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


To Bleek,
What you say is very true.:-)

FireNet
Posting Whiz in Training
258 posts since May 2004
Reputation Points: 108
Solved Threads: 7
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You