C#猜数字编程0-9

来源:百度知道 编辑:UC知道 时间:2024/06/19 19:23:07
不要太长 要准确!0到9之间的 正确了 就显示正确的次数 错了就继续

Random ra = new Random();
int rndInt = ra.Next(1, 100);
Console.WriteLine("请输入一个整数(范围从1-10)");
Console.WriteLine("如果要退出,请输入0!");
int inputInt = int.Parse(Console.ReadLine());
if (inputInt >= 1 & inputInt <= 10)
{

while (!(inputInt == 0))
{

if (inputInt == rndInt)
{
Console.WriteLine("恭喜你,猜对了!");
Console.WriteLine("继续输入Y,退出输入N!");
string inputNext = Console.ReadLine();
if (inputNext == "Y")
rndInt = ra.Next(1, 100);
else
return;
}
else if (inputInt < rndInt)
Console.WriteLine("你猜小了!");
else