双色球——最终版

namespace 刘老师双色球
{
    class Program
    {
        static void Main(string[] args)
        {
            int count = 0;
            Console.WriteLine("请输入你的双色球号码");
            ArrayList Ual = new ArrayList();
            for (int i = 0; i < 7; i++)
            {
                Ual.Add(Console.ReadLine());
            }
            while (true)//一直循环
            {
                //生成随机彩票
                Random r = new Random();//创建随机函数r
                ArrayList ral = new ArrayList();//
                while (true)
                {
                    if (ral.Count == 6)
                    {
                        break;
                    }
                    else
                    {
                        int temp = r.Next(1, 34);
                        if (!ral.Contains(temp))
                        {
                            ral.Add(temp);
                        }
                      
                    }
                }
                ral.Sort();
                Console.Write("红球为:");
                for (int i = 0; i < ral.Count; i++)
                {
                    Console.Write(ral[i] + "\t");
                }
                int x = r.Next(1, 17);
                Console.Write("蓝球为:" + x + "\n");

                //下面开始判断中奖个数
                int zjs = 0;
                for (int i = 0; i < 6; i++)
                {
                    if (ral.Contains(Convert.ToInt32(Ual[i].ToString())))
                    {
                        zjs++;
                    }
                }
                Console.WriteLine("红球中了" + zjs + "个");
              
                if (x == Convert.ToInt32(Ual[6]))
                {
                    Console.Write("蓝球相同");
                }
                count++;// 买的注数
                if (zjs == 6 && x == Convert.ToInt32(Ual[6]))
                {
                    Console.WriteLine("恭喜你中大奖了,当前总共花销为:" + (count * 2));
                }
            }//while的花括号
            Console.ReadLine();
        }
    }
}

posted @ 2015-04-08 21:49  XCml  阅读(202)  评论(0编辑  收藏  举报