zoukankan      html  css  js  c++  java
  • 自制*开奖小程序

    while (true)
                {
                    //数组:一组同类型的数据,数组是有长度的,数组是有索引的,索引从0开始
    
                    int[] shuzu = new int[7];//定义了一个长度为6的int类型的数组
                    Random r = new Random();
    
                    for (int i = 0; i < 6; i++)//循环生成六个数
                    {
                        shuzu[i] = r.Next(1, 34);//生成一个数
    
                        bool isok = false;
                        for (int j = 0; j < i; j++)//比较是否跟之前的书相等
                        {
                            if (shuzu[j] == shuzu[i])
                            {
                                isok = true;
                            }
                        }
                        if (isok)
                        {
                            i--;//后退一步
                            continue;
                        }
    
                    }
                    shuzu[6] = r.Next(1, 17);
    
                    //输入你的号码
                    Console.Write("请输入红球6个,蓝球1个,逗号隔开:");
    
                    string shuru = Console.ReadLine();
                    string[] ren = shuru.Split(',');
                    //判断中了几个红球
                    int count = 0;
                    for (int i = 0; i < 6; i++)
                    {
                        for (int j = 0; j < 6; j++)
                        {
                            if (int.Parse(ren[i]) == shuzu[j])
                            {
                                count++;
                            }
                        }
                    }
                    //判断蓝球中没中
                    bool islan = false;
                    if (int.Parse(ren[6]) == shuzu[6])
                    {
                        islan = true;
                    }
    
                    //输出电脑随机的中奖号码
                    foreach (int a in shuzu)
                    {
                        Console.Write(a + " | ");
                    }
    
                    //判断中几等奖
                    if (count == 6 && islan)
                    {
                        Console.Write("一等奖");
                    }
                    else if (count == 6 && !islan)
                    {
                        Console.Write("二等奖");
                    }
                    else if (count == 5 && islan)
                    {
                        Console.Write("三等奖");
                    }
                    else if ((count == 4 && islan) || (count == 5 && !islan))
                    {
                        Console.Write("四等奖");
                    }
                    else if ((count == 3 && islan) || (count == 4 && !islan))
                    {
                        Console.Write("五等奖");
                    }
                    else if ((count == 2 && islan) || (count == 1 && islan) || (count == 0 && islan))
                    {
                        Console.Write("五块钱");
                    }
                    else
                    {
                        Console.Write("别再买了");
                    }
    
    
    
                
                    Console.ReadLine();
                
    
                } 
  • 相关阅读:
    zTree根据json选中节点,并且设置其他节点不可选
    点击一次按钮,发生多次ajax请求
    sublimeText3 中配置sass环境,并将编译后文件保存到指定文件夹
    MD5加密
    c# Http请求之HttpClient
    xml与object 之间的ORM
    wpf和winform的那点区别
    c# http请求ajax页面
    c# https请求
    python爬虫框架Pyspider初次接触
  • 原文地址:https://www.cnblogs.com/wang-kaifeng/p/4810500.html
Copyright © 2011-2022 走看看