1. 程式人生 > >C#--if else基礎訓練輸入參觀的月份,輸出實行的淡季或旺季票價

C#--if else基礎訓練輸入參觀的月份,輸出實行的淡季或旺季票價

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

namespace test2
{
    class Program
    {
        static void Main(string[] args)
        {
 
           int month;  // 參觀的月份
        
            Console.WriteLine("請輸入你參觀故宮的月份:");
            month = int.Parse(Console.ReadLine());

            if ((month >= 11 && month <= 12) || (month >= 1 && month <= 3))
            {
                Console.WriteLine("現在是淡季,門票全價為40元,學生20元。");
             }
             else if ((month >= 4 && month <= 10))
            {
                Console.WriteLine("現在是旺季,門票全價為60元,學生20元。");
            }
            else
            {
                Console.WriteLine("對不起,你輸入的月份不正確!");
            }
            Console.ReadLine();
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace test3
{
    class Program
    {
        static void Main(string[] args)
        {
            String type;
            int month;  // 參觀的月份
            Console.WriteLine("請輸入你是屬於哪類參觀者:\n1-1.2米以下兒童\n2-大中小學生\n3-離休人員\n4-老年人\n5-其他");
            type = Console.ReadLine();

            Console.WriteLine("請輸入你參觀故宮的月份:");
            month = int.Parse(Console.ReadLine());
           
            // 根據選擇的型別,輸出享受的優惠
            switch (type)
            {
                case "1":
                case "3":
                    Console.WriteLine("可以享受免票優惠!");
                    break;
                case "2":
                    Console.WriteLine("優惠後票價20元!");
                    break;
                case "4":
                    Console.WriteLine("可以享受半價優惠!");
                    break;
                default:
                    Console.WriteLine("不能享受優惠!");
                    break;
            }

            if ((month >= 11 && month <= 12) || (month >= 1 && month <= 3))
            {
                Console.WriteLine("現在是淡季,門票全價為40元,學生20元。");
            }
            else if ((month >= 4 && month <= 10))
            {
                Console.WriteLine("現在是旺季,門票全價為60元,學生20元。");
            }
            else
            {
                Console.WriteLine("對不起,你輸入的月份不正確!");
            }
            Console.ReadLine();
        }
        
    }
}