我需要显示获得 6 所需的平均滚动数,以及该平均值所基于的 6 数。我认为我遇到的问题是这部分代码?所以我想要我认为我拥有的平均卷数作为变量 AVGroll。平均值所基于的六位数应该是 loopcount 变量。
AVGroll = AVGroll + loopcount;
average = AVGroll / loopcount;
试图尽可能地注释我的代码以使其可读。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace CE0721a
{
class Tut4_7
{
public void run()
{
// Random number generator
Random rndm = new Random();
//declaring number for Random Number Generator
int number;
// average number of runs
int average;
//declaring loopcount starts at 1
int loopcount = 1;
//Average roll starts at 0
int AVGroll = 0;
//Variable if it continues
int progcontinue;
//Start lable
Start:
do
{
number = rndm.Next(6) + 1;
Console.WriteLine(number);
Console.ReadKey();
if (number < 6)
{
loopcount++;
}
} while (number != 6);
AVGroll = AVGroll + loopcount;
average = AVGroll / loopcount;
Console.WriteLine("The roll count is:");
Console.WriteLine(loopcount);
Console.WriteLine("average");
Console.WriteLine(AVGroll);
Console.WriteLine("press 1 to continue or 0 to exit");
progcontinue = (int.Parse(Console.ReadLine()));
if (progcontinue > 0)
{
loopcount = 1;
goto Start;
}
else
{
}
}
}
}