`
txf2004
  • 浏览: 6875211 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

C#猜字游戏

 
阅读更多

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
show();
}
static void show()
{
try
{
Console.WriteLine("请输入一个0-100的数字:");
Random ram = new Random();
int a = ram.Next(0, 101);
for (int i = 1; i <= 10; i++)
{
int b = Convert.ToInt32(Console.ReadLine());

if (b > a)
{
if (b>100)
{
Console.WriteLine("error,请输入指定范围内的数字!"); break;
}
Console.WriteLine("比你输入的数要小,继续努力");
}
if (b<a)
{
if (b < 0)
{
Console.WriteLine("error,请输入指定范围内的数字!"); break;
}
Console.WriteLine("比你输入的数要大,继续努力");
}

if(b==a)
{
Console.WriteLine("恭喜你猜对了,奖励你一朵小红花"); break;
}
if (i==10)
{
Console.WriteLine("笨蛋,10次都没猜对!");
}
}
}
catch (Exception e)
{
Console.WriteLine("error!",e.Message);
}


}
}
}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics