CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

switch case with a range

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
wynnet



Joined: 02 Dec 2003
Posts: 15

View user's profile Send private message

switch case with a range
PostPosted: Wed Mar 31, 2004 4:15 pm     Reply with quote

How do I write a switch case with a range?
switch (number) {
case 1: tax_1() ;
break;
case 2:
case 3:
case 4: tax_2()
break;
case 10: /* a range of case 10 to case 99 */
case 11:
case 12:
..
..
case 99: tax_ 11percent()
break;
default: /* example 00 or Hex Letter */
break;
}
How do I do a shortcut instead of type case 10,case 11,..case 99?
Darren Rook



Joined: 06 Sep 2003
Posts: 287
Location: Milwaukee, WI

View user's profile Send private message Send e-mail

PostPosted: Wed Mar 31, 2004 5:00 pm     Reply with quote

Don't use case, use if/else.
random_person
Guest







PostPosted: Wed Mar 31, 2004 5:03 pm     Reply with quote

i'm not sure theres a way to do that with the CCSC compiler.

it looks like in your example, you are testing for ranges...so why not just use the if/else if structure to test for ranges?

if you don't like that idea, why not put in some code before the switch that sets number = to a specific integer if it is in a given range. ie...
Code:

if (number >=10 && number <100) number = 99;

switch(number) {...case 4:tax_2();break;case 99:tax_3;break;...};


if you can't change number, then use some temp variable.
wynnet



Joined: 02 Dec 2003
Posts: 15

View user's profile Send private message

switch case with a range
PostPosted: Thu Apr 01, 2004 11:47 am     Reply with quote

thank
I use
if (number >=10 && number <100) number = 99;

it helps me from making human typo error.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group