我正在玩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)。并输入另一个选择,如果我按任何其他键,它将退出该程序。
答案 0 :(得分: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");
}
答案 1 :(得分: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;
}
}
答案 2 :(得分: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");
}
.....
}