C#結構體

來源:互聯網
上載者:User

標籤:

class Program    {        struct student        {            public int code;            public string name;            public double score;        }        public int rz=0;        public int dz = 0;        public string bj(int a , int b)        {            int d = a - b;            if (d==-2||d==1)            {                return "人";            }            else if (d==2||d==-1)            {                return "電腦";            }            else            {                return "和";            }        }        static void Main(string[] args)        {            //輸入人的100以內的數            //隨機電腦100以內的數            //若人的數大,給人加分            //若電腦的大,給電腦加分            //若相等,兩個都加分            //Random ran = new Random();            //int dian = ran.Next(101);            //Console.Write("請輸入一個100以內的整數:");            //int ren = int.Parse(Console.ReadLine());            //Program hanshu = new Program();            //string s = hanshu.daxiao(ren,dian);            //switch (s)            //{             //    case "人":            //        hanshu.renzong++;            //        break;            //    case "電腦":            //        hanshu.dianzong++;            //        break;            //    case "和":            //        hanshu.renzong++;            //        hanshu.dianzong++;            //        break;            //}            //Console.WriteLine("人的分數:{0},電腦的分數:{1}",hanshu.renzong,hanshu.dianzong);            //Console.ReadLine();            //建立一個儲存學生學號、姓名、成績的結構體            //根據人數分別輸入,然後放置在集合中,            //所有資料錄入完成之後,進行列印            //ArrayList al = new ArrayList();            //Console.Write("請輸入學生人數:");            //int a = int.Parse(Console.ReadLine());            //for (int i = 0; i < a; i++)            //{            //    student code = new student();            //    Console.Write("請輸入學號:");            //    code.code = int.Parse(Console.ReadLine());            //    Console.Write("請輸入姓名:");            //    code.name = Console.ReadLine();            //    Console.Write("請輸入成績:");            //    code.score = double.Parse(Console.ReadLine());            //    al.Add(code);            //}            //Console.WriteLine("輸入完畢,您輸入的正確");            //Console.ReadLine();            //for (int i = 0; i < a; i++)            //{            //    student code = (student)al[i];            //    Console.WriteLine("學號" + code.code + "名字" + code.name + "成績" + code.score);            //}            //Console.ReadLine();                           //猜拳,5局3勝            //要求使用公用變數            Random sj = new Random();            Program zdy=new Program();            while (zdy.rz < 3 && zdy.dz < 3)            {                Console.WriteLine("請輸入剪刀石頭布的數字編碼(1為剪刀,2為石頭,3為布):");                int a = int.Parse(Console.ReadLine());                int b = sj.Next(1,4);                string jg = zdy.bj(a, b);                switch (jg)                {                    case "人":                        zdy.rz++;                        Console.WriteLine("本局你獲勝");                        break;                    case "電腦":                        zdy.dz++;                        Console.WriteLine("本局電腦獲勝");                        break;                    case "和":                        Console.WriteLine("本局平局");                        break;                }                            }            if (zdy.rz > zdy.dz)            {                Console.WriteLine("你贏了");            }            else            {                Console.WriteLine("你輸了");            }            Console.ReadLine();

 

C#結構體

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.