Guest User

Untitled

a guest
Feb 2nd, 2019
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.80 KB | None | 0 0
  1. using System;
  2.  
  3. namespace delthis
  4. {
  5.     using System;
  6.  
  7.     namespace NewHome
  8.     {
  9.         class Program
  10.         {
  11.             static void Main(string[] args)
  12.             {
  13.                 string typeOfFlowers = Console.ReadLine();
  14.                 int numFlowers = int.Parse(Console.ReadLine());
  15.                 double budget = double.Parse(Console.ReadLine());        
  16.  
  17.                 double priceForOneFlower = 0;
  18.                 int threshold = 0;
  19.                 bool isPositiveThreshold = false;
  20.                 double coefficient = 0;
  21.                
  22.                 if (typeOfFlowers == "Roses")      //roses > 80 --> 10% discount
  23.                 {
  24.                     priceForOneFlower = 5;
  25.                     isPositiveThreshold = true;
  26.                     threshold = 80;
  27.                     coefficient = 0.9;
  28.                 }
  29.                 else if (typeOfFlowers == "Dahlias")     //dahlias > 90 --> 15% discount
  30.                 {
  31.                     priceForOneFlower = 3.8;
  32.                     isPositiveThreshold = true;
  33.                     threshold = 90;
  34.                     coefficient = 0.85;
  35.                 }
  36.                 else if (typeOfFlowers == "Tulips")     //tulips > 80 --> 15% discount
  37.                 {
  38.                     priceForOneFlower = 2.8;
  39.                     isPositiveThreshold = true;
  40.                     threshold = 80;
  41.                     coefficient = 0.85;
  42.                 }
  43.                 else if (typeOfFlowers == "Narcissus")    //narcissus < 120 --> price * 15%
  44.                 {
  45.                     priceForOneFlower = 3;
  46.                     isPositiveThreshold = false;
  47.                     threshold = 120;
  48.                     coefficient = 1.15;
  49.                 }
  50.                 else if (typeOfFlowers == "Gladiolus")   //gladiolus < 80 --> price * 20%
  51.                 {
  52.                     priceForOneFlower = 2.5;
  53.                     isPositiveThreshold = false;
  54.                     threshold = 80;
  55.                     coefficient = 1.2;
  56.                 }
  57.  
  58.                 var totalPrice = priceForOneFlower * numFlowers;
  59.                 if ((isPositiveThreshold && numFlowers > threshold) ||
  60.                     (!isPositiveThreshold && numFlowers < threshold))
  61.                 {
  62.                     totalPrice *= coefficient;
  63.                 }
  64.  
  65.                 double neededMoney = budget - totalPrice;
  66.                 if (neededMoney >= 0)
  67.                 {
  68.                     Console.WriteLine($"Hey, you have a great garden with {numFlowers} {typeOfFlowers} and {neededMoney:f2} leva left.");
  69.                 }
  70.                 else
  71.                 {
  72.                     Console.WriteLine($"Not enough money, you need {Math.Abs(neededMoney):f2} leva more.");
  73.                 }
  74.                
  75.             }
  76.         }
  77.     }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment