# How to use "switch" to perform large numbers cases?

This is a discussion on How to use "switch" to perform large numbers cases? within the C Programming forums, part of the General Programming Boards category; How to use switch to make following output?( Issit required me to defined each cases from 0,1,2,3...39=BAD ...... 100 ) ...

1. ## How to use "switch" to perform large numbers cases?

How to use switch to make following output?( Issit required me to defined each cases from 0,1,2,3...39=BAD ...... 100 )

Score Comment
40~69 Poor
70~89 Good
90~100 Excellent!!

2. It would probably be better here to use nested If/else statements.
Code:
```if (blah >= 90)
{do this};
else if (blah >= 70)
{do this};
else if (blah >= 40)
{do this};
else
{do this};```

3. Yup nested if-else is better but i desire to know the "switch" way

4. >>Issit required me to defined each cases from 0,1,2,3...39=BAD ...... 100
Yes. A four part if/else if/else statement is just a smidge better than a 100 case switch/case statement or something weird. You can also sneak around with tables, if you really wanted to.
Code:
```char *getScore(double score)
{
double  scores[] = {39.0, 69.0, 89.0, 100.0};
char   *scorestrings[] = {"BAD", "Poor", "Good", "Excellent!!"};
int     i;

for (i = 0; i < 4; i++)
{
if (score <= scores[i])
return scorestrings[i];
}

return "Invalid score";
}```

5. oh, i see. Thanks again salem and fellows..!!