static void Main(string[] args)
{
string i = null;
do
{
Console.Write("请输入一个整数(范围为1~100)\n如果要退出,请输入0!否则输入1!");
i = Console.ReadLine();
if (i.Trim().Equals("0"))
{
return;
}
} while (!i.Trim().Equals("1"));
start:
Random ra = new Random();
int rndInt = ra.Next(1, 100);
int input = 0;
do
{
Console.Write("输入你猜的数值:");
i = Console.ReadLine();
if (!int.TryParse(i, out input))
{
continue;
}
if (input > rndInt)
{
Console.Write("猜大了\n\n");
}
else if (input < rndInt)
{
Console.Write("猜小了\n\n");
}
} while (input != rndInt);
Console.Write("恭喜你,猜对了!\n\n");
do
{
Console.Write("若继续猜测输入Y,若退出则输入N!\n请输入:");
i = Console.ReadLine();
if (i.Trim().Equals("n", StringComparison.OrdinalIgnoreCase))
{
return;
}
if (i.Trim().Equals("y", StringComparison.OrdinalIgnoreCase))
{
goto start;
}
} while (!i.Trim().Equals("1"));
}
温馨提示:内容为网友见解,仅供参考