void main()
{
int n=15,s,d=0
while(1)
{
printf("请滚乎输入1-35的数:")
scanf("%d",&s)
if(s>=1&&s<=35)
{
if(s<n)
{
printf("偏小!")
d++
}
else if(s>n)
{
printf("偏大!")
d++
}
else
{
if(d==0)
{
printf("猜了一次答案就对了悔备橘!\n")
break
}
else
{
printf("猜了%d次答案对了!\n",d)
break
}
}
}
printf("\n")
}
}
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"))
}
using Systemclass Program
{
static void Main(string[] args)
{
Random r=new Random()
int guessNumber=0,inputNumber=0
bool isExit=false
while(isExit==false)
{
guessNumber=r.Next(1,100)
while(true)
{
try
{
Console.Clear()
Console.WriteLine("闷中输入一个1到100之间的数 ")
inputNumber=Convert.ToInt32(Console.ReadLine())
if(inputNumber>guessNumber)
{
Console.WriteLine("大了"裤铅)
System.Threading.Thread.Sleep(500)
}
else if(inputNumber<guessNumber)
{
Console.WriteLine("小了")
System.Threading.Thread.Sleep(500)
}
else
{
Console.WriteLine("猜对了胡罩好,是否还玩Y-N?")
string result=Console.ReadLine()
if(result.ToUpper()=="N")
{
isExit=true
}
break
}
}
catch
{
Console.WriteLine("输入有误")
}
}
}
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)