Possible Duplicate:
How do I select a range of values in a switch statement?
c++ cannot appear in a constant-expression|
What I'm trying to do is generate a random number, and, depending on the value of the number, write out "Common", "Rare", or "Very Rare". Can somebody help me?
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
int a;
srand(time(0));
a = 1 + (rand()%10);
switch (a)
{
case (a >= 0 && a <= 5):
cout << "Common";
break;
case (a >= 6 && a <= 8):
cout << "Rare";
break;
case (a >= 9 && a <= 10):
cout << "Very rare";
break;
default:
break;
}
return 0;
}