猜数字c#

猜数字

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Random rdm = new Random();
            int guess = rdm.Next(0, 101);
            Console.WriteLine("猜测一个0到100之间的整数");
            int num = -1;
            int i = 0;
            while (num != guess)
            {
                Console.Write("第{0}次猜,请输入一个整形数字:", i);
                num = Convert.ToInt32(Console.ReadLine());
                if (num < guess)
                {
                    Console.WriteLine("太小");
                }
                else if (num > guess)
                {
                    Console.WriteLine("太大");
                }
                else
                {
                    Console.WriteLine("恭喜你猜对");
                }
                ++i;
            }
        }
    }
}

在这里插入图片描述

发布了73 篇原创文章 · 获赞 0 · 访问量 971

猜你喜欢

转载自blog.csdn.net/weixin_44584702/article/details/104747772