Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace ExcursionCalculator
- {
- class Program
- {
- public static void Main()
- {
- int people = int.Parse(Console.ReadLine());
- string season = Console.ReadLine();
- double price = 0;
- if (season == "spring")
- {
- if (people <= 5)
- {
- price = 50;
- }
- else
- {
- price = 48;
- }
- }
- else if (season == "summer")
- {
- if (people <= 5)
- {
- price = 48.50;
- }
- else
- {
- price = 45;
- }
- }
- else if (season == "autumn")
- {
- if (people <= 5)
- {
- price = 60;
- }
- else
- {
- price = 49.50;
- }
- }
- else if (season == "winter")
- {
- if (people <= 5)
- {
- price = 86;
- }
- else
- {
- price = 85;
- }
- }
- if (season == "summer")
- {
- price *= 0.85;
- }
- else if (season == "winter")
- {
- price *= 1.08;
- }
- Console.WriteLine($"{price * people:f2} leva.");
- }
- }
- }
- РЕШЕНИЕ СЪС SWITCH И ТЕРНАРЕН ОПЕРАТОР:
- using System;
- namespace ExcursionCalculator
- {
- class Program
- {
- public static void Main()
- {
- int people = int.Parse(Console.ReadLine());
- string season = Console.ReadLine();
- double price = 0;
- switch (season)
- {
- case "spring":
- price = people <= 5? 50 : 48;
- break;
- case "summer":
- price = people <= 5 ? 48.50 : 45;
- break;
- case "autumn":
- price = people <= 5 ? 60 : 49.50;
- break;
- case "winter":
- price = people <= 5 ? 86 : 85;
- break;
- }
- price *= season == "summer" ? 0.85 : season == "winter" ? 1.08 : 1;
- Console.WriteLine($"{price * people:f2} leva.");
- }
- }
- }
- РЕШЕНИЕ САМО С ТЕРНАРЕН ОПЕРАТОР:
- using System;
- namespace ExcursionCalculator
- {
- class Program
- {
- public static void Main()
- {
- int people = int.Parse(Console.ReadLine());
- string season = Console.ReadLine();
- double price = (season == "spring" ? (people <= 5 ? 50 : 48)
- : season == "summer" ? (people <= 5 ? 48.50 : 45)
- : season == "autumn" ? (people <= 5 ? 60 : 49.50)
- : season == "winter" ? (people <= 5 ? 86 : 85) : 0)
- * (season == "summer" ? 0.85 : season == "winter" ? 1.08 : 1) * people;
- Console.WriteLine($"{price:f2} leva.");
- }
- }
- }
Add Comment
Please, Sign In to add comment