c++ - 如何选择要随机化的数组中的特定数字?C++
问题描述
我有一个骰子分配给代码,基本上我们滚动了 6 个骰子。一旦滚动,所有值(除了单个 1 或 5)都可以再次滚动。
为了使整个骰子随机化的功能已经完成,我只展示了一小部分代码,它专门要求用户输入要重新掷骰子的内容(例如,第 5 个骰子)。然后,我选择骰子的第 5 个元素并再次随机化数字。
我的意图是能够像这样创建:
您已掷出: 5 3 6 4 2 1 [1] [2] [3] [4] [5] [6] 您要重掷哪些骰子?(1-6) //输入
//然后在选择要重掷的骰子之后,(例如骰子,2-5)
5 5 2 3 1 1 [1] [2] [3] [4] [5] [6]
你的回合已经结束,你从两个 5 中获得 100 分,从两个 1 中获得 200 分。
如何创建一个可以接收输入的代码,然后可以使用它来选择要再次随机化的数组的第 n 个元素?谢谢
cout << "All dices you've rolled are scoring dices!\n";
cout << "Do you wanto to [q]uit, [r]oll or [s]score";
cin >> question;
if (question == 'q') {
system("pause");
exit();
}
else if (question == 'r') {
cout << "Which dice(s) do you want to set aside? \n";
cout << "(1-6) Enter which dice(s) without any spaces";
cin >> choice;
for (int i : choice) {
/* This is the place where I enter the code to be able to randomize the nth element of an array with another function */
}
}
}
}
解决方案
推荐阅读
- python - 为什么 Azure 内容审查器无法检测到自定义术语?
- python - 如何在基于函数的视图中查询模型管理器以获取 single_page(detail.html)
- android - 布局在圆形下巴上被裁剪
- jwt - JWT 提供什么好处?
- javascript - 我如何使用 Php 值作为 carsoule Slider 的 ID
- mule - 如何修复“org.apache.cxf.interceptor.Fault: null” [Mule/CXF]
- angular - 如何使用 RxJS BehaviorSubject 在组件之间传递数字而不是字符串
- html - 是否可以引用 HTML 文档中其他地方定义的 SVG?
- docker - 将 Thorntail 日志记录配置到 System.out
- javascript - 在浏览器上打开 html 时 Javascript 文件不起作用