Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace PastryShop
- {
- class Program
- {
- static void Main(string[] args)
- {
- string type = Console.ReadLine();
- double quantity = double.Parse(Console.ReadLine());
- int date = int.Parse(Console.ReadLine());
- double price = 0;
- if (date <= 15)
- {
- if (type == "Cake")
- {
- price = 24.0;
- }
- else if (type == "Souffle")
- {
- price = 6.66;
- }
- else if (type == "Baklava")
- {
- price = 12.60;
- }
- }
- else if (date > 15)
- {
- if (type == "Cake")
- {
- price = 28.7;
- }
- else if (type == "Souffle")
- {
- price = 9.8;
- }
- else if (type == "Baklava")
- {
- price = 16.98;
- }
- }
- double sum = quantity * price;
- if (date <= 22 && sum >= 100 && sum <= 200)
- {
- sum -= sum * 0.15;
- }
- else if (date <= 22 && sum > 200)
- {
- sum -= sum * 0.25;
- }
- if (date <= 15)
- {
- sum -= sum * 0.1;
- }
- Console.WriteLine($"{sum:f2}");
- }
- }
- }
- Решение с тернарен оператор:
- using System;
- namespace PastryShop
- {
- class Program
- {
- static void Main(string[] args)
- {
- string product = Console.ReadLine();
- int volume = int.Parse(Console.ReadLine());
- int date = int.Parse(Console.ReadLine());
- double sum = (product == "Cake" ? (date > 15 ? 28.70 : 24)
- : product == "Souffle" ? (date > 15 ? 9.80 : 6.66)
- : product == "Baklava" ? (date > 15 ? 16.98 : 12.60) : 0) * volume;
- sum *= date <= 22 && sum >= 100 && sum <= 200 ? 0.85 : 1;
- sum *= date <= 22 && sum > 200 ? 0.75 : 1;
- sum *= date <= 15 ? 0.9 : 1;
- Console.WriteLine($"{sum:f2}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement