Click to See Complete Forum and Search --> : switch case statement


(...A13...)
09-24-2002, 07:12 PM
Hey there!
I wonder if there is anyone help me in coverting this if statement into a
correct switch case statement

if(average<80)
printf("The grade is C");
if(average >= 80 && average <90)
printf("The grade is B");
if(average >= 90)
printf("The grade is A")

hope to get your replay as soon as possible.
Thanks

James Curran
09-25-2002, 09:45 AM
There is no really practical way of doing it. Basically, it would have
to be:

switch (average)
{
case 100:
case 99:
case 98:
case 97:
// etc
case 91:
case 90:
printf("The grade is A");
break;
case 89:
case 88:

and so on...

If you divide average by 10 first, you can reduce the number of cases, but
on the whole, the if()s are your best bet.

--
Truth,
James Curran
www.NovelTheory.com (Personal)
www.NJTheater.com (Professional)
www.aurora-inc.com (Day job)


"(...A13...)" <alooaa13@hotmail.com> wrote in message
news:3d90f172$1@10.1.10.29...
>
> Hey there!
> I wonder if there is anyone help me in coverting this if statement into a
> correct switch case statement
>
> if(average<80)
> printf("The grade is C");
> if(average >= 80 && average <90)
> printf("The grade is B");
> if(average >= 90)
> printf("The grade is A")
>
> hope to get your replay as soon as possible.
> Thanks