gpt4 book ai didi

c++ - 制作随机数稀有系统并且它不起作用

转载 作者:太空宇宙 更新时间:2023-11-04 15:47:55 27 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
How do I select a range of values in a switch statement?
c++ cannot appear in a constant-expression|

我想做的是生成一个随机数,然后根据数字的值,写出“常见”、“稀有”或“非常稀有”。有人可以帮助我吗?

#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;
}

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com