TeMePyT

Untitled

Feb 3rd, 2018
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 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 Fruit_Shop_2
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. string fruit = Console.ReadLine().ToLower();
  14. string day = Console.ReadLine().ToLower();
  15. double quantity = double.Parse(Console.ReadLine());
  16. double price = -1.0;
  17.  
  18. var fruitsDays = new Dictionary<string, double>
  19. {
  20. {"banana", 2.50},
  21. {"apple", 1.20},
  22. {"orange", 0.85},
  23. {"grapefruit", 1.45},
  24. {"kiwi", 2.70},
  25. {"pineapple", 5.50},
  26. {"grapes", 3.85},
  27. };
  28. var fruitsWeekend = new Dictionary<string, double>
  29. {
  30. {"banana", 2.70},
  31. {"apple", 1.25},
  32. {"orange", 0.90},
  33. {"grapefruit", 1.60},
  34. {"kiwi", 3.00},
  35. {"pineapple", 5.60},
  36. {"grapes", 4.20},
  37. };
  38. try
  39. {
  40. if (day == "monday") price = quantity * fruitsDays[fruit];
  41. else if (day == "tuesday") price = quantity * fruitsDays[fruit];
  42. else if (day == "wednesday") price = quantity * fruitsDays[fruit];
  43. else if (day == "thursday") price = quantity * fruitsDays[fruit];
  44. else if (day == "friday") price = quantity * fruitsDays[fruit];
  45. else if (day == "saturday") price = quantity * fruitsWeekend[fruit];
  46. else if (day == "sunday") price = quantity * fruitsWeekend[fruit];
  47.  
  48. if (price >= 0)
  49. {
  50. Console.WriteLine("{0:f2}", price);
  51. }
  52. else
  53. {
  54. Console.WriteLine("error");
  55. }
  56. }
  57. catch (KeyNotFoundException)
  58.  
  59. {
  60. Console.WriteLine("error");
  61. }
  62. }
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment