c#其他未按预期工作 { 随机r=新随机(); int电流=0; int-noa=0; while(当前!=6){ 电流=r.Next(1,7); noa+=1; Console.WriteLine(当前+“已滚动”); } 如果(noa>=10) { WriteLine(“你很不走运,花了“+noa+”次掷6!”); } 如果(noa

c#其他未按预期工作 { 随机r=新随机(); int电流=0; int-noa=0; while(当前!=6){ 电流=r.Next(1,7); noa+=1; Console.WriteLine(当前+“已滚动”); } 如果(noa>=10) { WriteLine(“你很不走运,花了“+noa+”次掷6!”); } 如果(noa,c#,if-statement,while-loop,C#,If Statement,While Loop,因此 { Random r = new Random(); int current = 0; int noa = 0; while (current != 6) { current =r.Next(1,7); noa += 1; Console.WriteLine(current + " has been rolled.");

因此

    {
        Random r = new Random();
        int current = 0;
        int noa = 0;
        while (current != 6) {
            current =r.Next(1,7);
                noa += 1;
                Console.WriteLine(current + " has been rolled.");
        }

        if (noa >= 10)
        {
            Console.WriteLine("You were unlucky and it took you "+ noa + " times to roll a 6!");
        }
        if (noa <= 5)
        {
            Console.WriteLine("You were quite lucky and it took you " + noa + " times to roll a 6!");
        }
        else
        {
            Console.WriteLine("It took you " + noa + " times to roll a 6!");
        }

        Console.ReadKey();


    }
}

如果(noa 5

您必须使其成为
elseif

if (noa <= 5)
{
    Console.WriteLine("You were quite lucky and it took you " + noa + " times to roll a 6!");
}
else
{
    Console.WriteLine("It took you " + noa + " times to roll a 6!");
}
如果(noa>=10)
{
WriteLine(“你很不走运,花了“+noa+”次掷6!”);
}

否则,如果(noa@tagito)是你拥有它的方式(与此相反)将>=10和下一个if/else视为两个独立的语句。如果CarbineCoder输入的else-if将所有3个语句合并在一起,那么它将对它们进行计算,而不是检查>=10然后检查Thank you,现在我明白了,但是如果我需要4个if怎么办?我可以通过“if;else if;else if;else;?您只需在最后一条
else
语句之前再添加一条
else if
if (noa >= 10)
{
    Console.WriteLine("You were unlucky and it took you "+ noa + " times to roll a 6!");
}
else if (noa <= 5)
{
    Console.WriteLine("You were quite lucky and it took you " + noa + " times to roll a 6!");
}
else
{
    Console.WriteLine("It took you " + noa + " times to roll a 6!");
}