Advertisement
Guest User

Untitled

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