利用if else 来计算车费

 static void Main(string[] args)
        {
            while (true)
            {
                double x,y;
                Console.Write("请输入坐车的距离:");
                x = Convert.ToDouble(Console.ReadLine());
                if (x>0&&x <= 3)
                {
                    Console.WriteLine("您的车费为8元");
                }
                else if (x > 3 && x <= 5)
                {
                    Console.WriteLine("您的车费为"+(8+(x-3)*1.2)+"元");  //注意运算要加括号
                }

                else if (x > 5)
                {
                    Console.WriteLine("您的车费为" + (10.4+ (x - 5) * 1.5) + "元");
                }

                else
                {
                    Console.WriteLine("请输入正确的距离");
                }


                Console.ReadLine();

            }

posted @ 2015-03-28 13:33  XCml  阅读(268)  评论(0编辑  收藏  举报