| | |
switch/case statement
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
Hi all,
Someone is going to laugh at me for this one.
Can you have two arguments in a switch case statement?
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; }
use if, if else and else.You can have multiple checks in a if statement
C++ Syntax (Toggle Plain Text)
if(condition == true || condition < high) if(condition == true && condition < high)
•
•
Join Date: Mar 2004
Posts: 1,620
Reputation:
Solved Threads: 51
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
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
•
•
Join Date: Mar 2004
Posts: 28
Reputation:
Solved Threads: 0
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
peace
To Kc0arf,
Not necessary I belive.Especially when only two conditions are being compared or multiple non dependants
it will be needed if you are going in for dependants
To Bleek,
What you say is very true.:-)
Not necessary I belive.Especially when only two conditions are being compared or multiple non dependants
C++ Syntax (Toggle Plain Text)
if(condirion1 || condirion2 || condirion3)
it will be needed if you are going in for dependants
C++ Syntax (Toggle Plain Text)
if(condirion1 || (condirion2 && condirion3) || condition4)
To Bleek,
What you say is very true.:-)
![]() |
Similar Threads
- Switch case with String not working! (C)
- Reputed number problem switch case statement (VB.NET)
- scientific calculator using switch case statement (C++)
- switch case (C)
- Help with switch/case statement navigation (PHP)
- Switch Case Statement (Java)
Other Threads in the C++ Forum
- Previous Thread: practice(newbie)
- Next Thread: Advantages of C++ SAFEARRAY: Explain
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char class classes code coding compile compiler console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news node number output parameter pointer problem program programming project python read recursion recursive reference return rpg string strings struct temperature template templates test text text-file tree unix url variable vector visualstudio win32 windows winsock word wordfrequency wxwidgets






