DEV Community

Ivan Ivanov
Ivan Ivanov

Posted on

12. Trade Commissions (Switch Construction)

using System;

namespace TradeCommissions_Switch
{
internal class Program
{
    static void Main(string[] args)
    {
        string city = Console.ReadLine();
        double sales = double.Parse(Console.ReadLine());

        switch (city)
        {
            case "Sofia":
                if (sales >= 0 && sales <= 500)
                {
                    sales *= 0.05;
                    Console.WriteLine($"{sales:F2}");
                }
                else if (sales > 500 && sales <= 1_000)
                {
                    sales *= 0.07;
                    Console.WriteLine($"{sales:F2}");
                }
                else if (sales > 1_000 && sales <= 10_000)
                {
                    sales *= 0.08;
                    Console.WriteLine($"{sales:F2}");
                }
                else if (sales > 10_000)
                {
                    sales *= 0.12;
                    Console.WriteLine($"{sales:F2}");
                }
                else
                {
                    Console.WriteLine("error");
                }
                break;

            case "Varna":
                if (sales >= 0 && sales <= 500)
                {
                    sales *= 0.045;
                    Console.WriteLine($"{sales:F2}");
                }
                else if (sales > 500 && sales <= 1_000)
                {
                    sales *= 0.075;
                    Console.WriteLine($"{sales:F2}");
                }
                else if (sales > 1_000 && sales <= 10_000)
                {
                    sales *= 0.1;
                    Console.WriteLine($"{sales:F2}");
                }
                else if (sales > 10_000)
                {
                    sales *= 0.13;
                    Console.WriteLine($"{sales:F2}");
                }
                else
                {
                    Console.WriteLine("error");
                }
                break;

            case "Plovdiv":
                if (sales >= 0 && sales <= 500)
                {
                    sales *= 0.055;
                    Console.WriteLine($"{sales:F2}");
                }
                else if (sales > 500 && sales <= 1_000)
                {
                    sales *= 0.08;
                    Console.WriteLine($"{sales:F2}");
                }
                else if (sales > 1_000 && sales <= 10_000)
                {
                    sales *= 0.12;
                    Console.WriteLine($"{sales:F2}");
                }
                else if (sales > 10_000)
                {
                    sales *= 0.145;
                    Console.WriteLine($"{sales:F2}");
                }
                else
                {
                    Console.WriteLine("error");
                }
                break;

            default:
                Console.WriteLine("error");
                break;
        }
    }
}
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)