Mim1111

Untitled

Jan 22nd, 2022
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.92 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.  
  10.  
  11. string input = "";
  12. string product = "";
  13. double coint = 0;
  14. double sum = 0;
  15. double sumProdicts = 0;
  16.  
  17. while ((input=Console.ReadLine())!= "Start")
  18. {
  19. coint = double.Parse(input);
  20. switch (coint)
  21. {
  22. case 0.1:
  23. case 0.2:
  24. case 0.5:
  25. case 1:
  26. case 2:
  27. sum += coint;
  28. break;
  29. default:
  30. Console.WriteLine($"Cannot accept {coint}");
  31. break;
  32. }
  33. }
  34. const double Nuts = 2.0;
  35. const double Water = 0.7;
  36. const double Crisps = 1.5;
  37. const double Soda = 0.8;
  38. const double Coke = 1.0;
  39. while ((product=Console.ReadLine())!="End")
  40. {
  41.  
  42.  
  43. switch (product)
  44. {
  45. case "Nuts":
  46. if (sum < Nuts)
  47. {
  48. Console.WriteLine("Sorry, not enough money");
  49. break;
  50. }
  51. else
  52. {
  53. Console.WriteLine($"Purchased {product.ToLower()}");
  54. sum -= 2.0;
  55. }
  56. break;
  57. case "Water":
  58. if (sum < Water)
  59. {
  60. Console.WriteLine("Sorry, not enough money");
  61. break;
  62. }
  63. else
  64. {
  65. Console.WriteLine($"Purchased {product.ToLower()}");
  66. sum -= 0.7;
  67. }
  68.  
  69. break;
  70. case "Crisps":
  71. if (sum < Crisps)
  72. {
  73. Console.WriteLine("Sorry, not enough money");
  74. break;
  75. }
  76. else
  77. {
  78. Console.WriteLine($"Purchased {product.ToLower()}");
  79. sum -= 1.5;
  80. }
  81.  
  82. break;
  83. case "Soda":
  84. if (sum < Soda)
  85. {
  86. Console.WriteLine("Sorry, not enough money");
  87. break;
  88. }
  89. else
  90. {
  91. Console.WriteLine($"Purchased {product.ToLower()}");
  92. sum -= 0.8;
  93. }
  94.  
  95. break;
  96. case "Coke":
  97. if (sum < Coke)
  98. {
  99. Console.WriteLine("Sorry, not enough money");
  100. break;
  101. }
  102. else
  103. {
  104. Console.WriteLine($"Purchased {product.ToLower()}");
  105. sum -= 1.0;
  106. }
  107. break;
  108. default:
  109. Console.WriteLine("Invalid product");
  110. break;
  111. }
  112. }
  113. Console.WriteLine($"Change: {sum:f2}");
  114.  
  115. }
  116. }
  117. }
  118.  
Advertisement
Add Comment
Please, Sign In to add comment