您的位置:首页 > 编程语言 > C#

猜数字游戏(简单C#实现)

2015-02-05 16:47 357 查看
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace 猜数字
{
class Program
{
static void Main(string[] args)
{
new Program().play();
}
void play()
{
System.Random r = new System.Random(); //生成随机种子
int j = r.Next(1, 100);
int i;
int n = 1;
System.Console.WriteLine("请猜猜随机数是多少?(1-100)");
do
{
i = int.Parse(System.Console.ReadLine());
if (i == j)
System.Console.WriteLine("恭喜您在第{0}次猜对了!", n);
else
{
if (i < j)
{
System.Console.WriteLine("第{0}次,猜小了", n);
System.Console.WriteLine("再试试:");
}
else
{
System.Console.WriteLine("第{0}次,猜大了", n);
System.Console.WriteLine("再试试:");
}
}
n++;
} while (i != j);
System.Console.ReadLine();
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: