随机从1到100中得到一个数,请你猜一下。
using System;
namespace ConsoleApp3
{
class Program
{
static void Main(string[] args)
{
Random rdm = new Random();
int guess = rdm.Next(0, 101);
Console.WriteLine("猜一个1到100的数字。");
for (int i = 1; ; i++)
{
Console.WriteLine("第{0}次猜,请输入数字:", i);
int num = int.Parse(Console.ReadLine());
if (num == guess)
{
Console.WriteLine("猜对了,好厉害");
break;
}
else if (num < guess)
{
Console.WriteLine("好可惜,小了");
continue;
}
else
{
Console.WriteLine("好可惜,大了");
continue;
}
}
}
}
}
来源:CSDN
作者:weixin_45774295
链接:https://blog.csdn.net/weixin_45774295/article/details/104759140