Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace FruitShop
- {
- class Program
- {
- static void Main(string[] args)
- {
- string fruit = Console.ReadLine();
- string day = Console.ReadLine();
- double quantity = double.Parse(Console.ReadLine());
- if (day == "Monday" || day == "Tuesday" || day == "Wednesday" || day == "Thursday" || day == "Friday")
- {
- if (fruit == "banana")
- {
- Console.WriteLine($"{2.5 * quantity:F2}");
- }
- else if (fruit == "apple")
- {
- Console.WriteLine($"{1.2 * quantity:F2}");
- }
- else if (fruit == "orange")
- {
- Console.WriteLine($"{0.85 * quantity:F2}");
- }
- else if (fruit == "grapefruit")
- {
- Console.WriteLine($"{1.45 * quantity:F2}");
- }
- else if (fruit == "kiwi")
- {
- Console.WriteLine($"{2.7 * quantity:F2}");
- }
- else if (fruit == "pineapple")
- {
- Console.WriteLine($"{5.5 * quantity:F2}");
- }
- else if (fruit == "grapes")
- {
- Console.WriteLine($"{3.85 * quantity:F2}");
- }
- else
- {
- Console.WriteLine("error");
- }
- }
- else if (day == "Saturday" || day == "Sunday")
- {
- if (fruit == "banana")
- {
- Console.WriteLine($"{2.7 * quantity:F2}");
- }
- else if (fruit == "apple")
- {
- Console.WriteLine($"{1.25 * quantity:F2}");
- }
- else if (fruit == "orange")
- {
- Console.WriteLine($"{0.9 * quantity:F2}");
- }
- else if (fruit == "grapefruit")
- {
- Console.WriteLine($"{1.6 * quantity:F2}");
- }
- else if (fruit == "kiwi")
- {
- Console.WriteLine($"{3 * quantity:F2}");
- }
- else if (fruit == "pineapple")
- {
- Console.WriteLine($"{5.6 * quantity:F2}");
- }
- else if (fruit == "grapes")
- {
- Console.WriteLine($"{4.2 * quantity:F2}");
- }
- else
- {
- Console.WriteLine("error");
- }
- }
- else
- {
- Console.WriteLine("error");
- }
- }
- }
- }
- РЕШЕНИЕ С ТЕРНАРЕН ОПЕРАТОР:
- using System;
- namespace FruitShop
- {
- class Program
- {
- static void Main(string[] args)
- {
- string fruit = Console.ReadLine();
- string day = Console.ReadLine();
- double quantity = double.Parse(Console.ReadLine());
- double totalSum =
- (day == "Monday" || day == "Tuesday" || day == "Wednesday" || day == "Thursday" || day == "Friday" ?
- (fruit == "banana" ? 2.5 : fruit == "apple" ? 1.2 : fruit == "orange" ? 0.85 : fruit == "grapefruit" ? 1.45
- : fruit == "kiwi" ? 2.7 : fruit == "pineapple" ? 5.5 : fruit == "grapes" ? 3.85 : 0) :
- day == "Saturday" || day == "Sunday" ?
- (fruit == "banana" ? 2.7 : fruit == "apple" ? 1.25 : fruit == "orange" ? 0.9 : fruit == "grapefruit" ? 1.6
- : fruit == "kiwi" ? 3 : fruit == "pineapple" ? 5.6 : fruit == "grapes" ? 4.2 : 0) : 0) * quantity;
- Console.WriteLine(totalSum == 0 ? "error" : $"{totalSum:F2}");
- }
- }
- }
Add Comment
Please, Sign In to add comment