c#常量变量

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

namespace x1808汪敏_阶段练习_19_4_3
{
    class Program
    {
        static void Main(string[] args)
        {
            int jihui = 4;
            //2、对登录验证的修改--直到型
            //定义符号常量--重复率高、经常修改的常量
            const string NAME = "admin";
            const string PASS = "123456";
            //1、定义变量--密码为字符串
            string name, pass;
            //4、验证用户名和密码的正确性
            //技巧:有方法判断两个字符串相等
            do
            {
                if (jihui == 1) { break; }
                Console.WriteLine("您还有{0}次机会", jihui - 1);
                //2、输入--提示信息
                Console.WriteLine("请输入你的用户名:");
                name = Console.ReadLine();
                Console.WriteLine("请输入你的密码:");
                pass = Console.ReadLine();
                jihui--;
            } while (!name.Equals(NAME) || !pass.Equals(PASS));
            if (jihui != 1)
            {


                //主菜单
                menu();
                //趣味程序
                int tm = 0;
                while (tm != 4)
                {
                    switch (tm)
                    {
                        case 0:
                            Console.WriteLine("请输入你要打开题目的数字(1-4)");
                            tm = int.Parse(Console.ReadLine()); break;
                        //----------------------------------------------------
                        case 1:
                            int year, month, day;
                            Console.WriteLine("请输入年份");
                            year = int.Parse(Console.ReadLine());
                            Console.WriteLine("请输入月份");
                            month = int.Parse(Console.ReadLine());
                            Console.WriteLine("请输入日期");
                            day = int.Parse(Console.ReadLine());
                            Console.WriteLine("{0}年{1}月{2}日是今年的第{3}天", year, month, day, tianshu(year, month, day));
                            Console.WriteLine("请输入你要打开题目的数字(1-4)");
                            tm = int.Parse(Console.ReadLine()); break;
                        //-----------------------------------------------------
                        case 2:
                            int num1, num2;
                            Console.WriteLine("请输入两个整数");
                            num1 = int.Parse(Console.ReadLine());
                            num2 = int.Parse(Console.ReadLine());
                            Console.WriteLine("最大值是:" + max(num1, num2));
                            Console.WriteLine("请输入你要打开题目的数字(1-4)");
                            tm = int.Parse(Console.ReadLine()); break;
                        //-----------------------------------------------------
                        case 3:
                            aite();
                            Console.WriteLine("请输入你要打开题目的数字(1-4)");
                            tm = int.Parse(Console.ReadLine());
                            break;
                    }
                }
                Console.WriteLine("游戏结束");
            }
            else { Console.Write("没有机会了"); }
            //暂停界面
            Console.ReadLine();  
        }
       
        /// <summary>
        /// 主菜单
        /// </summary>
        public static void menu()
        {
            Console.WriteLine("--------------------------------");
            Console.WriteLine("-          趣味程序            -");
            Console.WriteLine("-    1、生活中的趣味题         -");
            Console.WriteLine("-    2、数字趣味题             -");
            Console.WriteLine("-    3、图形趣味题             -");
            Console.WriteLine("-    4、退出                   -");
            Console.WriteLine("--------------------------------");
        }
        public static int max(int a, int b)
        {
            int m;
            if (a < b) m = b;
            else m = a;
            return m;
        }
        /// <summary>
        /// 计算日期
        /// </summary>
        /// <param name="ye"></param>
        /// <param name="mo"></param>
        /// <param name="da"></param>
        /// <returns></returns>
        public static int tianshu(int ye, int mo, int da)
        {
            //由于month-1个月是完整的,先求出这个月份的总天数
            int days = 0;
            for (int i = 1; i <= mo - 1; i++)
            {
                switch (i)
                {
                    case 1:
                    case 3:
                    case 5:
                    case 7:
                    case 8:
                    case 10:
                    case 12: days = days + 31; break;
                    case 4:
                    case 6:
                    case 9:
                    case 11: days = days + 30; break;
                    case 2:
                        if ((ye % 4 == 0 && ye % 100 != 0) || ye % 400 == 0)
                        {
                            days = days + 29;
                        }
                        else
                        {
                            days = days + 28;
                        }
                        break;
                }
            }
            days = days + da;
            return days;
        }
        /// <summary>
        /// 输出图形
        /// </summary>
        public static void aite()
        {
            int n, m;
            Console.WriteLine("请输入一个整数");
            n = Convert.ToInt32(Console.ReadLine());
            m = n + 1;
            for (int j = 1; j <= m; j++)//外层循环
            {
                for (int i = 1; i <= j * 2 - 1; i++)//内层循环
                {
                    Console.Write("@");
                }
                Console.WriteLine();
                Console.WriteLine();
            }
        }
    }
}

 

posted @ 2024-04-09 19:29  困到很想醒  阅读(4)  评论(0编辑  收藏  举报