Hello,

I was given a question a few few days back to write a program that lets a user enter a value for an angle and quadrant in which the angle lies is printed using switch statement.

I was able to make this program using if-else very easily but making it with switch statement is a problem..

I tried using

```
switch (angle)
{
case (angle>=0 && angle<=90):
printf("1st quadrant");
break;
.
.
.
.
}
```

and so on....(where angle is the variable in which the value of angle is stored )

it gives me the error "Case constant required in statement switch"...

it works if I write it like case 90:,case 45: and all other constant values..

but,i can't go writing all 360 cases for all angles,can I???

So,is there any way to check a condition in switch statement??

---

Thanks in advance..

The error message tells it all. The case needs to be a constant...Like

1,2,3,4,5...or

```
#define one 1
const unsigned long two 2;
switch(angle)
{
case:1
{}
case:two
{}
}
```

dear gerard4143,

Thanks for the snappy reply.

I figured out what you are saying.But,the problem is that i can't go on writing all 360 cases for 360 values of an angle.

what I'm seeking is a solution for shortening the program length by somehow testing the condition in the case...

Is there any way of doing that??

But,the problem is that i can't go on writing all 360 cases for 360 values of an angle.

what I'm seeking is a solution for shortening the program length by somehow testing the condition in the case...

Is there any way of doing that??

that's where if else conditions shines, is it really required to use only a switch statement?

dear zeroliken,

that's where my problem started...

I have to use only switch statement..

There is a single arithmetic operation you can use to convert the ranges 0-89, 90-179, 180-269, 270-359 into the values 0, 1, 2, 3, respectively. The result represents the quadrant; 0 would be the first quadrant.

There is a single arithmetic operation you can use to convert the ranges 0-89, 90-179, 180-269, 270-359 into the values 0, 1, 2, 3, respectively. The result represents the quadrant; 0 would be the first quadrant.

@death_oclock

Thank you very much...

it solved my problem...

Thanks Again...