Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace TradeCommissions
- {
- class Program
- {
- static void Main(string[] args)
- {
- string town = Console.ReadLine();
- double sum = double.Parse(Console.ReadLine());
- if (town == "Sofia")
- {
- if (sum > 0 && sum <= 500)
- {
- Console.WriteLine($"{0.05 * sum:F2}");
- }
- else if ( sum > 500 && sum <= 1000)
- {
- Console.WriteLine($"{0.07 * sum:F2}");
- }
- else if (sum > 1000 && sum <= 10000)
- {
- Console.WriteLine($"{0.08 * sum:F2}");
- }
- else if (sum > 10000)
- {
- Console.WriteLine($"{0.12 * sum:F2}");
- }
- else
- {
- Console.WriteLine("error");
- }
- }
- if (town == "Varna")
- {
- if (sum > 0 && sum <= 500)
- {
- Console.WriteLine($"{0.045 * sum:F2}");
- }
- else if (sum > 500 && sum <= 1000)
- {
- Console.WriteLine($"{0.075 * sum:F2}");
- }
- else if (sum > 1000 && sum <= 10000)
- {
- Console.WriteLine($"{0.10 * sum:F2}");
- }
- else if (sum > 10000)
- {
- Console.WriteLine($"{0.13 * sum:F2}");
- }
- else
- {
- Console.WriteLine("error");
- }
- }
- if (town == "Plovdiv")
- {
- if (sum > 0 && sum <= 500)
- {
- Console.WriteLine($"{0.055 * sum:F2}");
- }
- else if (sum > 500 && sum <= 1000)
- {
- Console.WriteLine($"{0.08 * sum:F2}");
- }
- else if (sum > 1000 && sum <= 10000)
- {
- Console.WriteLine($"{0.12 * sum:F2}");
- }
- else if (sum > 10000)
- {
- Console.WriteLine($"{0.145 * sum:F2}");
- }
- else
- {
- Console.WriteLine("error");
- }
- }
- else if(town != "Sofia" && town != "Varna" && town != "Plovdiv")
- {
- Console.WriteLine("error");
- }
- }
- }
- }
- РЕШЕНИЕ С ТЕРНАРЕН ОПЕРАТОР:
- using System;
- namespace TradeCommissions
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- string town = Console.ReadLine();
- double sum = double.Parse(Console.ReadLine());
- double commission =
- ( sum > 0 && sum <= 500 ? (town == "Sofia" ? 0.05 : town == "Varna" ? 0.045 : town == "Plovdiv" ? 0.055 : 0)
- : sum > 500 && sum <= 1000 ? (town == "Sofia" ? 0.07 : town == "Varna" ? 0.075 : town == "Plovdiv" ? 0.08 : 0)
- : sum > 1000 && sum <= 10000 ? (town == "Sofia" ? 0.08 : town == "Varna" ? 0.1 : town == "Plovdiv" ? 0.12 : 0)
- : sum > 10000 ? (town == "Sofia" ? 0.12 : town == "Varna" ? 0.13 : town == "Plovdiv" ? 0.145 : 0) : 0) * sum;
- Console.WriteLine(commission == 0 ? "error" : $"{commission:F2}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement