using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BehindClosedDoors
{
class Program
{
static void Main(string[] args)
{
string userValue;
Console.WriteLine("Hello, Welcome to Behind Closed Doors");
Console.WriteLine("A fun and exciting game");
Console.WriteLine("Roll Two dice and the add the value's together and enter that number");
userValue = Console.ReadLine();
do while (userValue == "2")
{
Console.WriteLine("Kiss");
Console.WriteLine("Now roll another number");
Console.ReadLine();
}
while ((userValue = Console.ReadLine()) == "3");
{
Console.WriteLine("Give");
Console.WriteLine("Now roll another number");
Console.ReadLine();
}
while ((userValue = Console.ReadLine()) == "4")
{
Console.WriteLine("Foot Rub");
Console.WriteLine("Now roll another number");
Console.ReadLine();
}
while (userValue == "2" + "3" + "4")
{
//
}
// else if (userValue == "5")
}
}
}
我正在尝试这样做当我运行此代码时,我可以根据需要输入2 3或4次,并在没有控制台关闭的情况下获取该文本。现在我可以选择两个,然后在第三个关闭控制台。
答案 0 :(得分:3)
我认为你需要带开关的单循环:
do
{
userValue = Console.ReadLine();
switch(userValue)
{
case "2": //..
case "3": //..
case "4": //..
}
}while (userValue == "2" || userValue == "3" || userValue == "4")
答案 1 :(得分:1)
您正在检查“2”+“3”+“4”,即“234”作为字符串。
你可能想要像
这样的东西userValue == "2" || userValue == "3" || userValue == "4"