-1

我正在玩 C#,我做了这个。

{
        string wichOp;
        Console.WriteLine("Kaj je toni?");
        Console.WriteLine("Izber med:   -A   -B   -C   -D   -E");
        wichOp = Console.ReadLine();

        wichOp = wichOp.ToLower();
        if (wichOp == "a")
        {
            Console.Write("Toni je BK");
        }
        else if (wichOp == "b")
        {
            Console.Write("Toni je PEDER");
        }
        else if (wichOp == "c")
        {
            Console.Write("Toniju Baloni");
        }
        else if (wichOp == "d")
        {
            Console.Write("Toni je buzi");
        }
        else if (wichOp == "e")
        {
            Console.Write("TONI ŠAMPION");
        }
        else
            Console.WriteLine("Nisi vnesil pravilno izbiro");

    }
}

}

我想要做的是通过按键(R)我可以跳回到我的选择(A,B,C,D,E)。并输入另一个选择,如果我按下任何其他键,它将退出程序。

4

3 回答 3

1
    static void Main(string[] args)
    {
        string wichOp;
        bool running = true;

        while (running)
        {

            Console.WriteLine("Kaj je toni?");
            Console.WriteLine("Izber med:   -A   -B   -C   -D   -E");
            wichOp = Console.ReadLine();

            wichOp = wichOp.ToLower();
            if (wichOp == "a")
            {
                Console.Write("Toni je BK");
            }
            else if (wichOp == "b")
            {
                Console.Write("Toni je PEDER");
            }
            else if (wichOp == "c")
            {
                Console.Write("Toniju Baloni");
            }
            else if (wichOp == "d")
            {
                Console.Write("Toni je buzi");
            }
            else if (wichOp == "e")
            {
                Console.Write("TONI ŠAMPION");
            }
            else
                Console.WriteLine("Nisi vnesil pravilno izbiro");

            Console.WriteLine("\n\nPress r to repeat, other input will close the Program");
            string input = Console.ReadLine();
            if (input != "r")
                running = false;
        }
    }
于 2013-10-21T20:49:19.513 回答
1
string wichOp = "r";
while (wichOp == "r")
{
    Console.WriteLine("Kaj je toni?");
    Console.WriteLine("Izber med:   -A   -B   -C   -D   -E");
    wichOp = Console.ReadLine();
    wichOp = wichOp.ToLower();
    if (wichOp == "a")
    {
        Console.Write("Toni je BK");
    }
    else if (wichOp == "b")
    {
        Console.Write("Toni je PEDER");
    }
    else if (wichOp == "c")
    {
        Console.Write("Toniju Baloni");
    }
    else if (wichOp == "d")
    {
        Console.Write("Toni je buzi");
    }
    else if (wichOp == "e")
    {
        Console.Write("TONI ŠAMPION");
    }
    else if (wichOp != "r")
        Console.WriteLine("Nisi vnesil pravilno izbiro");
}
于 2013-10-21T20:40:15.130 回答
0

可能是这样的:

var wichOp = Console.ReadLine();
while(wichOp.Equals("R")) //WHILE "R"
{
        var wichOp = Console.ReadLine();
        if (wichOp == "a")
        {
            Console.Write("Toni je BK");
        }
        else if (wichOp == "b")
        {
            Console.Write("Toni je PEDER");
        }

      .....

}
于 2013-10-21T20:38:34.913 回答