Quote (Ideophobe @ Jun 28 2015 07:32pm)
so i got it to function anyway
is this really the best answer? theres no way to range these ? i mean what if there was a group that covered age 18-55, i sure wouldn't want to type out all those cases.
Code
switch (age)
{
case 2:
cout<< "toddler";
break;
case 3:
case 4:
case 5:
cout << "early childhood";
break;
case 6:
case 7:
cout << "young reader";
break;
case 8:
case 9:
case 10:
cout << "elementary";
break;
case 11:
case 12:
cout << "middle";
break;
case 13:
cout << "impossible";
break;
case 14:
case 15:
case 16:
cout << "high school";
break;
case 17:
case 18:
cout << "scholar";
break;
default : cout << "ineligible";
}
ty btw silver spot on advice, easy to understand, easy to implement.
Np,
unfortunately as to your question the answer is no not with a switch.
If you were able to use if else statements you could use ranges similar to the following:
Code
if(num > 0 && num <= 99)
{
dosomething();
}
else if(num >= 100 && num <= 199)
{
dosomethingagain();
}
else if (num >= 200 && num <= 299)
{
dosomethingelse();
}
else
{
dosomethingcompletelydifferent();
}
/e for syntax.
This post was edited by SilverMice on Jun 30 2015 06:39pm