need a way to use switch case

can I use a condition in a case such as......
switch (sqroo)
case x<0;
case x=0;
case x>0;
default

in such a manner.............Write your question here.

need this to calculate the roots of quadratic equation..

then is there any way to find roots of quadratic equation using switch case ,because i have got a problem to do so
You cannot form case statements that way. A case can only have a single value to check against... you cannot do > or < checks.

To do this, you will need an else/if chain. You cannot use a switch.
tnx
Like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
int casenum;
if(x == 0)
  casenum = 0;
else if(x > 0)
  casenum = 1;
else if(x < 0)
  casenum = 2;

switch(casenum){
   case 0:
          //do something
          break;
   case 1:
          //do something
          break; 
   case 2:
          //do something
          break;
  default:
          break;}






The third if is unnecessary. If x != 0 and x not > 0, then x can only be < 0.
1
2
3
4
5
6
if(x == 0)
  casenum = 0;
else if(x > 0)
  casenum = 1;
else 
  casenum = 2;



Topic archived. No new replies allowed.