硬币被抛出,直到一侧连续跌落 3 次

Coin is thrown until one side falls three times in a row

我是编程新手,在完成一项任务时遇到问题:

Coin is thrown until one side falls three times in a row

int throwing = 0;

int tail=0;
int head=0;
int counter= 0;
Random rnd = new Random();

do
{
    throwing = rnd.Next(1, 3);
    Console.WriteLine(bacanje);
    counter++;

    if (throwing == 1)
    {
        tail++;
    }
    else if (throwing == 2)
    {
        head++;
    }

} while (tail != 3 && head!= 3);

所以我的问题是它不想连续 3 次,当结果如下时程序退出:头、头、尾、头。它应该是:头,头,头。

不确定要更改什么代码,如果有人有什么建议,我将不胜感激。谢谢

如果投掷发生变化,您永远不会为另一个重置计数器,您只需将另一个重置为 0

if (throwing == 1)
{
    tail++;
    head = 0;
}
else if (throwing == 2)
{
    head++;
    tail = 0;
}