【发布时间】:2013-03-09 05:31:31
【问题描述】:
您好,我正在尝试为掷骰子游戏创建频率表。以下是我正在从事的项目的说明:
创建一个模拟滚动标准 6 面模具(编号 1 - 6)的应用程序。
- 模具应精确滚动 10,000 次。
- 10,000卷应该是用户输入的;询问他们想多久掷一次骰子
- 应根据 Random 类对象的输出,使用随机值确定掷骰子的值(请参阅下面的注释)。
- 在程序完成用户请求的滚动次数 (10,000) 后,应用程序应显示一个表格,显示每个骰子的滚动次数。
- 程序应该询问用户是否愿意模拟另一个掷骰子的会话。跟踪会话数。
现在我知道如何使用随机数类,但我被困在项目的汇总表部分,我只需要一些可以帮助我开始的东西
这是我目前在项目中的位置,你会看到我的汇总表没有意义:
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();
}
}
}
【问题讨论】: