Advertisement
rado84

SmallShop_Switch-Case

Jun 13th, 2016
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.13 KB | None | 0 0
  1. using System;
  2.  
  3. class Program
  4. {
  5. static void Main()
  6. {
  7. string product = Console.ReadLine().ToLower();
  8. string city = Console.ReadLine().ToLower();
  9. double quantity = double.Parse(Console.ReadLine());
  10. double price;
  11.  
  12. //SCROLL DOWN TO SEE THE SWITCH-CASE SOLUTION
  13. //SCROLL DOWN TO SEE THE SWITCH-CASE SOLUTION
  14.  
  15. //if (city == "sofia")
  16. //{
  17. // if (product == "coffee") { price = 0.50; }
  18. // else if (product == "water") { price = 0.80; }
  19. // else if (product == "beer") { price = 1.20; }
  20. // else if (product == "sweets") { price = 1.45; }
  21. // else if (product == "peanuts") { price = 1.60; }
  22. //}
  23.  
  24. //else if (city == "plovdiv")
  25. //{
  26. // if (product == "coffee") { price = 0.40; }
  27. // else if (product == "water") { price = 0.70; }
  28. // else if (product == "beer") { price = 1.15; }
  29. // else if (product == "sweets") { price = 1.30; }
  30. // else if (product == "peanuts") { price = 1.50; }
  31. //}
  32.  
  33. //else if (city == "varna")
  34. //{
  35. // if (product == "coffee") { price = 0.45; }
  36. // else if (product == "water") { price = 0.70; }
  37. // else if (product == "beer") { price = 1.10; }
  38. // else if (product == "sweets") { price = 1.35; }
  39. // else if (product == "peanuts") { price = 1.55; }
  40. //}
  41. //Console.WriteLine("{0:F2}", quantity * price);
  42.  
  43. switch (city)
  44. {
  45. case "sofia":
  46. if (product == "coffee")
  47. { price = 0.50; }
  48. Console.WriteLine("{0:F2}", quantity * price);
  49. break;
  50.  
  51. if (product == "water")
  52. { price = 0.80; }
  53. Console.WriteLine("{0:F2}", quantity * price);
  54. break;
  55.  
  56. if (product == "beer")
  57. { price = 1.20; }
  58. Console.WriteLine("{0:F2}", quantity * price);
  59. break;
  60.  
  61. if (product == "sweets")
  62. { price = 1.30; }
  63. Console.WriteLine("{0:F2}", quantity * price);
  64. break;
  65.  
  66. if (product == "peanuts")
  67. { price = 1.50; }
  68. Console.WriteLine("{0:F2}", quantity * price);
  69. break;
  70.  
  71.  
  72. case "plovdiv":
  73. if (product == "coffee")
  74. { price = 0.40; }
  75. Console.WriteLine("{0:F2}", quantity * price);
  76. break;
  77. if (product == "water")
  78. { price = 0.70; }
  79. Console.WriteLine("{0:F2}", quantity * price);
  80. break;
  81.  
  82. if (product == "beer")
  83. { price = 1.15; }
  84. Console.WriteLine("{0:F2}", quantity * price);
  85. break;
  86.  
  87. if (product == "sweets")
  88. { price = 1.30; }
  89. Console.WriteLine("{0:F2}", quantity * price);
  90. break;
  91.  
  92. if (product == "peanuts")
  93. { price = 1.50; }
  94. Console.WriteLine("{0:F2}", quantity * price);
  95. break;
  96.  
  97. case "varna":
  98. if (product == "coffee")
  99. { price = 0.45; }
  100. Console.WriteLine("{0:F2}", quantity * price);
  101. break;
  102.  
  103. if (product == "water")
  104. { price = 0.70; }
  105. Console.WriteLine("{0:F2}", quantity * price);
  106. break;
  107.  
  108. if (product == "beer")
  109. { price = 1.10; }
  110. Console.WriteLine("{0:F2}", quantity * price);
  111. break;
  112.  
  113. if (product == "sweets")
  114. { price = 1.35; }
  115. Console.WriteLine("{0:F2}", quantity * price);
  116. break;
  117.  
  118. if (product == "peanuts")
  119. { price = 1.55; }
  120. Console.WriteLine("{0:F2}", quantity * price);
  121. break;
  122. }
  123. }
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement