猜數字

02.// All rights reserved.                     
04.// 完成日期:2014年 11 月 16日           
05.// 版 本 號:v1.0                      
07.// 問題描述:創建一個程序來求三角形。該程序提示用戶輸入數據,然後顯示出三角形的三邊。          
08.// 輸入描述:三個三角形的邊長,代表數值           
09.// 程序輸出:辨別三角形 

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


namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int x = 0;


            int rndnum;
            Random rnd = new Random();
            rndnum = rnd.Next(1, 100);


            //這裏就是無限循環的開始,讓用戶一直猜
            while (true)
            {
                Console.WriteLine("請輸入你猜的數");
                x = Convert.ToInt32(Console.ReadLine());


                //用戶猜了一個數,我們斷定有3鍾情況
                if (x > rndnum)
                {
                    Console.WriteLine("對不起,你猜大了");
                }
                else if (x < rndnum)
                {
                    Console.WriteLine("對不起,你猜小了");
                }
                else
                {
                    //既不是大於,又不是小於,那就肯定是等於了
                    Console.WriteLine("你猜對了");
                    break;
                }


            }
            Console.Read();






        }
    }
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章