C#简单硬币翻转算法不起作用

0 c#

我的代码有问题,它应该询问用户他们想要翻硬币多少次,然后按照规定的次数翻转硬币,然后说出有多少条头和尾巴.问题是该程序询问硬币应被翻转多少次,然后在用户输入后关闭.有人可以告诉我我做错了什么.

static void Main(string[] args)
{
    int heads = 0;
    int tails = 0;
    int counter = 0;
    Random coinflip = new Random();

    Console.WriteLine("How many times would you like to flip a coin? ");
    counter = Convert.ToInt32 (Console.ReadLine());

    for (int i = 0; i < counter; i++)
    {
        int flip = coinflip.Next(1, 3);
        if (flip == 1)
        {
           heads++;
        }
        else 
        {
           tails++;
        }
    }

    Console.WriteLine("You flipped a coin " + counter 
       + "times " + "and you got " + heads + "heads and " + tails + "tails.");
    Console.WriteLine();
}
Run Code Online (Sandbox Code Playgroud)

小智 5

尝试改变决赛

Console.WriteLine()
Run Code Online (Sandbox Code Playgroud)

Console.ReadKey()
Run Code Online (Sandbox Code Playgroud)

这应该保持窗口打开,直到你键入一个键,让你看到你的输出.