dice c#控制台频率表
你好,我正在尝试为掷骰子游戏创建一个频率表。以下是我正在进行的项目的说明: 创建一个模拟滚动标准六面模具(编号1–6)的应用程序dice c#控制台频率表,c#,random,C#,Random,你好,我正在尝试为掷骰子游戏创建一个频率表。以下是我正在进行的项目的说明: 创建一个模拟滚动标准六面模具(编号1–6)的应用程序 模具应精确滚动10000次 10000卷应由用户输入;询问他们希望掷骰子的频率 掷骰子的值应根据随机类对象的输出使用随机值确定(请参见下面的注释) 程序完成滚动用户请求的次数(10000)后,应用程序应显示一个表格,显示每个骰子的滚动次数 该程序应询问用户是否希望模拟另一个滚动模具的过程。跟踪会话的数量 现在我知道如何使用random number类,但我被困在项
- 模具应精确滚动10000次李>
- 10000卷应由用户输入;询问他们希望掷骰子的频率
- 掷骰子的值应根据随机类对象的输出使用随机值确定(请参见下面的注释)李>
- 程序完成滚动用户请求的次数(10000)后,应用程序应显示一个表格,显示每个骰子的滚动次数
- 该程序应询问用户是否希望模拟另一个滚动模具的过程。跟踪会话的数量
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
namespace Dice
{
class Program
{
static void Main(string[] args)
{
Random rndGen = new Random();
Console.WriteLine("welcome to the ralph dice game");
Console.Clear();
Console.WriteLine("how many times do you want to roll");
int rollDice = int.Parse(Console.ReadLine());
for (int i = 0; i < rollDice; i++)
{
int diceRoll = 0;
diceRoll = rndGen.Next(1,7);
string table = " \tfrequency\tpercent";
table +="\n"+ "\t" + i + "\t" + diceRoll;
Console.WriteLine(table);
}//end for
Console.ReadKey();
}
}
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
使用系统数据;
名称空间骰子
{
班级计划
{
静态void Main(字符串[]参数)
{
Random rndGen=新的Random();
Console.WriteLine(“欢迎来到拉尔夫骰子游戏”);
Console.Clear();
Console.WriteLine(“您希望滚动多少次”);
int rollDice=int.Parse(Console.ReadLine());
for(int i=0;i
展示一张表格,显示每个骰子的掷骰次数
如果我理解正确,这意味着骰子得到1、2、3等的次数。。。您需要一个数组来存储所有结果计数,并在所有转鼓完成时输出
注意:未测试的代码
这确实帮了我的忙,但我仍然无法从数组中的掷骰子中调用这些数字并将它们放入表中。使用for循环读取数组<代码>用于(int i=0;i
int[] outcomes = new int[6];
// init
for (int i = 0; i < outcomes.Length; ++i) {
outcomes[i] = 0;
}
for (int i = 0; i < rollDice; i++)
{
int diceRoll = 0;
diceRoll = rndGen.Next(1,7);
outcomes[diceRoll - 1]++; //increment frequency.
// Note that as arrays are zero-based, the " - 1" part turns the output range
// from 1-6 to 0-5, fitting into the array.
}//end for
// print the outcome values, as a table
do {
// your code
// ask if user wish to continue
bool answer = // if user want to continue
} while (!answer);