Advertisement
clipro

Untitled

Oct 25th, 2018
535
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.29 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace exr_20_newHouse
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             // data input
  14.             string flower = Console.ReadLine().ToLower();
  15.             int numFlowers = int.Parse(Console.ReadLine());
  16.             decimal money = decimal.Parse(Console.ReadLine());
  17.  
  18.             // help variables
  19.             decimal totalCost = 0M;
  20.             string result = string.Empty;
  21.             decimal moneyLeft = 0M;
  22.  
  23.             // determine the price dependig on the flower choice
  24.                 switch (flower)
  25.                 {
  26.                     case "roses":
  27.                         totalCost = (numFlowers > 80) ? numFlowers * 5M * 0.90M : numFlowers * 5M;
  28.                         break;
  29.                     case "dahlias":
  30.                         totalCost = (numFlowers > 90) ? numFlowers * 3.80M * 0.85M : numFlowers * 3.80M;
  31.                         break;
  32.                     case "tulips":
  33.                         totalCost = (numFlowers > 80) ? numFlowers * 2.80M * 0.85M : numFlowers * 2.80M;
  34.                         break;
  35.                     case "narcissus":
  36.                         totalCost = (numFlowers < 120) ? numFlowers * 3.00M * 1.15M : numFlowers * 3.00M;
  37.                         break;
  38.                     case "gladiolus":
  39.                         totalCost = (numFlowers < 80) ? numFlowers * 2.50M * 1.20M : numFlowers * 2.50M;
  40.                         break;
  41.                 }
  42.  
  43.                 // compare budget to total cost
  44.                 moneyLeft = money - totalCost;
  45.                 if (moneyLeft > 0)
  46.                 {
  47.                     flower = flower.First().ToString().ToUpper() + flower.Substring(1);
  48.                     result = string.Format("Hey, you have a great garden with {0} {1} " +
  49.                         "and {2:F2} leva left.", numFlowers, flower, moneyLeft);
  50.                 }
  51.                 else
  52.                 {
  53.                     result = string.Format("Not enough money, you need {0:F2} leva more.",
  54.                         Math.Abs(moneyLeft));
  55.                 }
  56.  
  57.                 // print the result
  58.                 Console.WriteLine(result);
  59.         }
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement