C# 无法获取要插入到数组中的值
当我运行代码时,它会输出0表示所有内容。骰子的两个掷骰都应该得到总计并插入到阵列中。它应该掷骰子36000次,并统计结果,并以格式输出。它将在最后显示正确的格式,但是它不会将任何数据插入数组C# 无法获取要插入到数组中的值,c#,arrays,C#,Arrays,当我运行代码时,它会输出0表示所有内容。骰子的两个掷骰都应该得到总计并插入到阵列中。它应该掷骰子36000次,并统计结果,并以格式输出。它将在最后显示正确的格式,但是它不会将任何数据插入数组 using System; namespace DICE { public class DiceRoller { public static void Main() { // need to first create an object
using System;
namespace DICE
{
public class DiceRoller
{
public static void Main()
{ // need to first create an object
Random random = new Random();
// generate the int for use in the array
int dice1;
int dice2;
// i need an array to take these numbers and store them for use
int[] dicerolls = new int[13];
// I used 12 for the index for the max value but maybe I should use 6 for one dice at a time?
for (int roll = 0; roll <= 36000; roll++) ; //for loop to roll 36,000 times
{
dice1 = random.Next(6) + 1;
dice2 = random.Next(6) + 1;
int total = dice1 + dice2;
dicerolls[total]++;
//adds the 2 dice rolls to create one total for output
}
// then i need to display to frequency in which those numbers appear
Console.WriteLine("Sum Frequency Percentage");
for (int roll = 2; roll < 13; roll++)
{
double percent = (dicerolls[roll] / 36000) * 100;
Console.WriteLine("{0}\t {1}\t\t{2:0.00}", roll, dicerolls[roll], percent);
}
}
}
使用系统;
名称空间骰子
{
公营掷骰机
{
公共静态void Main()
{//需要先创建一个对象
随机=新随机();
//生成在数组中使用的int
int-1;
int-2;
//我需要一个数组来获取这些数字并存储它们以供使用
int[]dicells=新int[13];
//我用12作为最大值的索引,但也许我应该一次用6作为一个骰子?
对于(int roll=0;rollroll++);
Learn。在代码中,你会看到它在分号上停止,运行下一个块一次,然后继续,而不是再循环36000次。通过“在分号上停止”,我指的是36001次,它会突出显示分号,因为它在循环中不执行任何操作。如上所述,您有一个输入错误。因此,除第一个计数外,所有计数都保持为零。问题通常在此基础上结束。但您还有第二个错误,稍后计算平均值,这也会导致结果为0。请参阅dupl请详细说明该错误的原因和修复方法。