Advertisement
Guest User

Untitled

a guest
Jan 21st, 2020
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. using System;
  2.  
  3. namespace VendingMashine
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. string command = Console.ReadLine();
  10. double sum = 0.0;
  11. double price = 0.0;
  12.  
  13. while (command != "Start")
  14. {
  15. double coins = double.Parse(command);
  16. if (coins == 0.1 || coins == 0.2 || coins == 0.5 || coins == 1 || coins == 2)
  17. {
  18. sum += coins;
  19. }
  20. else
  21. {
  22. Console.WriteLine($"Cannot accept {coins}");
  23. }
  24. command = Console.ReadLine();
  25. }
  26. if (command == "Start")
  27. {
  28. while (command != "End")
  29. {
  30. command = Console.ReadLine();
  31. if (command == "End")
  32. {
  33. break;
  34. }
  35.  
  36. switch (command)
  37. {
  38. case "Nuts":
  39. price = 2.0;
  40. break;
  41. case "Water":
  42. price = 0.7;
  43. break;
  44. case "Crisps":
  45. price = 1.5;
  46. break;
  47. case "Soda":
  48. price = 0.8;
  49. break;
  50. case "Coke":
  51. price = 1.0;
  52. break;
  53.  
  54. default:
  55. Console.WriteLine("Invalid product");
  56. continue;
  57. break;
  58. }
  59.  
  60. if (price > sum && price!=0)
  61. {
  62. Console.WriteLine("Sorry, not enough money");
  63. //break;
  64. }
  65. else
  66. {
  67. Console.WriteLine($"Purchased {command.ToLower()}");
  68. sum -= price;
  69. price = 0;
  70. }
  71. }
  72. }
  73. Console.WriteLine($"Change: {sum:f2}");
  74. }
  75. }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement