Thank you for being a valued part of the CNET community. As of December 1, 2020, the forums are in read-only format. In early 2021, CNET Forums will no longer be available. We are grateful for the participation and advice you have provided to one another over the years.

Thanks,

CNET Support

General discussion

case statement VC++

Jan 20, 2007 7:06AM PST

switch(number)
{
case 4,5,6,7:
amount = 1;
break;
}
this isnt working, so how do I include 4-7 in one statement?

Discussion is locked

- Collapse -
Simple answer...
Jan 20, 2007 1:56PM PST

You don't. You could try this:

switch(number)
{
case 4:
case 5:
case 6:
case 7:
amount = 1;
break;
}

As a way to handle this where the other cases will "fall-through" to the one you want. Or you could use an if statement that would be easier.

- Collapse -
like this
Feb 11, 2007 3:02AM PST

switch(number)
{
case 4:
case 5:
case 6:
case 7:
amount = 1;
break;
default:
//may want a default value justin case
amount=-1;
}