#include<iostream>
using namespace std;
int My_rand(int x)
{
int y;
srand(x); //先设置随机种子数x
y = rand()%6 + 1; //调用rand()函数返回随机数
return y;
};
int main()
{
int x1, y1, x2, y2, sum;
bool go = true;
while (go)
{
cout << "Please input any int:" << endl;
cin >> x1;
y1 = My_rand(x1);
cout << "Please input another int:" << endl;
cin >> x2;
y2 = My_rand(x2);
sum = y1 + y2;
if (sum == 7 | sum == 11) go = false, cout << "Result is:" << sum << ",Game is win" << endl;
else if (sum == 2 | sum == 3 | sum == 12) go = false, cout << "Result is:" << sum << ",Game is fail" << endl;
else go = true, cout << "Result is:" << sum << ",Game is going" << endl;
}
}
C++ 使用rand()随机函数掷骰子
最新推荐文章于 2024-05-22 13:37:56 发布