猜数字小游戏(创建一个控制台。。。原理:random 产生随机数)

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

namespace eluosi
{
    class Program
    {
        static void Main(string[] args)
        {
            new Program().play();
        }
        void play()
        {
            Random r = new Random();
            int j = r.Next(1, 10);
            int i;
            int n=1;
            Console.Write("猜猜随机数是多少(1~10):");
            do
            {
                i = int.Parse(Console.ReadLine());
                if (i == j)
                {
                    Console.Write("恭喜你在第{0}次猜对了", n);
                }
                else
                {
                    if (i < j)
                    {
                        Console.Write("第{0}次,小了", n);
                    }
                    else
                    {
                        Console.Write("第{0}次,大了", n);
                    }
                }
                n++;
            } while (i != j);
            Console.ReadLine();
        }
    }
}

posted @ 2014-11-30 20:33  jhycwnqry  阅读(390)  评论(0编辑  收藏  举报