Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace NewHouse
- {
- class Program
- {
- static void Main(string[] args)
- {
- string flowers = Console.ReadLine();
- int num = int.Parse(Console.ReadLine());
- double budget = double.Parse(Console.ReadLine());
- double sum = 0;
- switch (flowers)
- {
- case "Roses":
- sum = num * 5;
- if (num > 80)
- {
- sum *= 0.9;
- }
- break;
- case "Dahlias":
- sum = num * 3.8;
- if (num > 90)
- {
- sum *= 0.85;
- }
- break;
- case "Tulips":
- sum = num * 2.8;
- if (num > 80)
- {
- sum *= 0.85;
- }
- break;
- case "Narcissus":
- sum = num * 3;
- if (num < 120)
- {
- sum *= 1.15;
- }
- break;
- case "Gladiolus":
- sum = num * 2.5;
- if (num < 80)
- {
- sum *= 1.2;
- }
- break;
- }
- if (budget >= sum)
- {
- Console.WriteLine($"Hey, you have a great garden with {num} {flowers} and {budget - sum:F2} leva left.");
- }
- else
- {
- Console.WriteLine($"Not enough money, you need {sum - budget:F2} leva more.");
- }
- }
- }
- }
- РЕШЕНИЕ С ТЕРНАРЕН ОПЕРАТОР:
- using System;
- namespace NewHouse
- {
- class Program
- {
- static void Main(string[] args)
- {
- string flowers = Console.ReadLine();
- int num = int.Parse(Console.ReadLine());
- double budget = double.Parse(Console.ReadLine());
- budget -= ( flowers == "Roses" ? (num > 80 ? 4.5 : 5)
- : flowers == "Dahlias" ? (num > 90 ? 3.23 : 3.8)
- : flowers == "Tulips" ? (num > 80 ? 2.38 : 2.8)
- : flowers == "Narcissus" ? (num < 120 ? 3.45 : 3)
- : flowers == "Gladiolus" ? (num < 80 ? 3 : 2.5) : 0) * num;
- Console.WriteLine(budget < 0 ? $"Not enough money, you need {Math.Abs(budget):F2} leva more."
- : $"Hey, you have a great garden with {num} {flowers} and {budget:F2} leva left.");
- }
- }
- }
Add Comment
Please, Sign In to add comment