Advertisement
dradoslavov89

Untitled

Sep 26th, 2018
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.51 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace _07.Vending_Machine
  7. {
  8. class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. string comand;
  13. double money = 0;
  14. while (true)
  15. {
  16. comand = Console.ReadLine();
  17.  
  18. if (comand == "Start")
  19. {
  20. break;
  21. }
  22. double coin = double.Parse(comand);
  23. if (coin == 0.1 || coin == 0.2 || coin == 0.5 || coin == 1 || coin == 2)
  24. {
  25. money += coin;
  26. }
  27. else
  28. {
  29. Console.WriteLine($"Cannot accept {coin}");
  30. }
  31.  
  32.  
  33. }
  34. while (true)
  35. {
  36.  
  37.  
  38. string drink = Console.ReadLine().ToLower();
  39. if (drink == "end")
  40. {
  41. Console.WriteLine($"Change: {money:F2}");
  42.  
  43. break;
  44. }
  45.  
  46. if (drink == "nuts")
  47. {
  48. if (money < 2)
  49. {
  50. Console.WriteLine("Sorry, not enough money");
  51.  
  52. }
  53. else
  54. {
  55. money -= 2;
  56.  
  57. Console.WriteLine("Purchased nuts");
  58.  
  59.  
  60. }
  61. }
  62. else if (drink == "water")
  63. {
  64. if (money < 0.7)
  65. {
  66. Console.WriteLine("Sorry, not enough money");
  67.  
  68.  
  69. }
  70. else
  71. {
  72. money -= 0.7;
  73.  
  74. Console.WriteLine("Purchased water");
  75.  
  76. }
  77.  
  78.  
  79. }
  80. else if (drink == "crisps")
  81. {
  82. if (money < 1.5)
  83. {
  84. Console.WriteLine("Sorry, not enough money");
  85.  
  86.  
  87. }
  88. else
  89. {
  90. money -= 1.5;
  91.  
  92. Console.WriteLine("Purchased crisps");
  93.  
  94. }
  95.  
  96. }
  97. else if (drink == "soda")
  98. {
  99. if (money < 0.8)
  100. {
  101. Console.WriteLine("Sorry, not enough money");
  102.  
  103.  
  104. }
  105. else
  106. {
  107. money -= 0.8;
  108.  
  109. Console.WriteLine("Purchased soda");
  110.  
  111.  
  112. }
  113.  
  114. }
  115. else if (drink == "coke")
  116. {
  117. if (money < 1)
  118. {
  119. Console.WriteLine("Sorry, not enough money");
  120.  
  121.  
  122. }
  123. else
  124. {
  125. money -= 1.0;
  126.  
  127. Console.WriteLine("Purchased coke");
  128.  
  129. }
  130.  
  131. }
  132. else
  133. {
  134. Console.WriteLine("Invalid product");
  135.  
  136. }
  137.  
  138.  
  139. }
  140.  
  141. }
  142.  
  143. }
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement