作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
<分区>
我几乎完成了一个掷骰子程序,我唯一的问题是由于我指定的数组大小,我无法输入超过 5000 次掷骰。虽然我想我可以简单地将数组的大小增加到一些荒谬的数字,但我不想这样做,而是使用基于输入的动态大小的数组 remainingRolls.
谁能帮忙?
注意:这是经过编辑的最终有效代码。
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
using namespace std;
int roller(){ // loop to simulate dice roll
int die1, die2;
int total;
die1 = rand()%6+1;
die2 = rand()%6+1;
total=die1+die2;
return total;
}
int main(){
int numberOfRolls;
int remainingRolls;
int eights=0; // declare counter array to hold frequencies of dice results
int i;
int value;
float percentage;
int currentRoll; // declare array for dice values
currentRoll= 0;
cout << "How many times will the dice be rolled?" << endl;
cin >> remainingRolls;// user input # of dice rolls
numberOfRolls = remainingRolls;// variable to hold number of rolls (for output)
for (i=0; remainingRolls >0; remainingRolls--){// loop to count frequency of each value
currentRoll = roller();// activate diceRoll function
if (currentRoll == 8){
eights++;
}
}
percentage = (eights*100/numberOfRolls);
cout << "The dice were rolled " << numberOfRolls << " times." << endl;
cout << "The value 8 came up " << eights << " times or " << percentage << "% of the time." << endl;
getch();
return 0;
}
我刚刚向自己介绍了 WebGL 和 Threejs,作为开始,我正在尝试创建一个 3D 骰子。我已经到了创建立方体的地步,但我真的不知道如何在立方体的面上放置数字,我能找到的只是如何更改颜色。我已经查
这就是我现在得到的...... var max = 7; var min = 1; $('#dice').click(function() { random = Math.floor(Math.r
我是 Unity 的新手,一直在尝试掷骰子。我遇到了一组教程,它们允许我创建一个 3d 模具(模具使用 Rigidbody 和 Mesh Collider)并编写脚本使其在空格键上滚动,如下所示: 骰
我是 JavaScript 新手,我需要一些想法/帮助来了解如何使我的脚本正常工作。所以我们的想法是,你掷两个骰子,通过按下“掷骰子”按钮然后按下重置按钮来重置整个 HTML 中的所有内容。 所以事情
我正在尝试构建一个掷骰子游戏,如果计算机自动掷出一对骰子,并且如果 cpu 掷出 7 或 11,则用户获胜。然而,如果用户掷出 2、3 或 12,他们将自动失败。如果用户滚动任何其他数字(4、5、6、
背景 如此处所述http://www.ericharshbarger.org/dice/#gofirst_4d12 , “先走”骰子是一组四个骰子,每个都有唯一的编号,因此: 任何两个或更多骰子都不会
我是一名优秀的程序员,十分优秀!