我要做的是生成一个随机数,并根据数字的值写出“常见”、“稀有”或“非常稀有”。有人可以帮助我吗?
#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;
}