Advertisement
AnastasiyaG

Untitled

Jan 21st, 2020
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.45 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Vending_machines
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. { bool coins = true;
  9. string coinsA = "";
  10. double money = 0;
  11. double total = 0;
  12. while (coins == true)
  13. { coinsA = Console.ReadLine();
  14. if (coinsA == "0.1" || coinsA == "0.2" || coinsA == "0.5" || coinsA == "1" || coinsA == "2")
  15. {
  16. money = Convert.ToDouble(coinsA);
  17. total += money;
  18. }
  19. else if(coinsA == "Start")
  20. { coins = false; }
  21. else if(coinsA != "0.1" || coinsA != "0.2" || coinsA != "0.5" || coinsA != "1" || coinsA != "2")
  22. {
  23. Console.WriteLine($"Cannot accept {coinsA}");
  24. }
  25. }
  26. bool order = true;
  27. string orderA = "";
  28. while (order == true)
  29. {
  30. orderA = Console.ReadLine();
  31. switch (orderA)
  32. {
  33. case "Nuts":
  34. total -= 2.0;
  35. if (total < 0)
  36. {
  37. Console.WriteLine("Sorry, not enough money");
  38. total += 2.0;
  39. }
  40. else
  41. { Console.WriteLine($"Purchased nuts" ); }
  42. break;
  43.  
  44. case "Water":
  45. total -= 0.7;
  46. if (total < 0)
  47. {
  48. Console.WriteLine("Sorry, not enough money");
  49. total += 0.7;
  50. }
  51. else
  52. { Console.WriteLine($"Purchased water"); }
  53. break;
  54.  
  55. case "Crisps":
  56. total -= 1.5;
  57. if (total < 0)
  58. {
  59. Console.WriteLine("Sorry, not enough money");
  60. total += 1.5;
  61. }
  62. else
  63. { Console.WriteLine($"Purchased crisps"); }
  64. break;
  65.  
  66. case "Soda":
  67. total -= 0.8;
  68. if (total < 0)
  69. {
  70. Console.WriteLine("Sorry, not enough money");
  71. total += 0.8;
  72. }
  73. else
  74. { Console.WriteLine($"Purchased soda"); }
  75. break;
  76.  
  77. case "Coke":
  78. total -= 1.0;
  79. if (total < 0)
  80. {
  81. Console.WriteLine("Sorry, not enough money");
  82. total += 1.0;
  83. }
  84. else
  85. { Console.WriteLine($"Purchased coke"); }
  86. break;
  87. case "End":
  88. order = false;
  89. break;
  90. default:
  91. Console.WriteLine("Invalid product");
  92. break;
  93. }
  94.  
  95. }
  96.  
  97. Console.WriteLine($"Change: {total:f2}");
  98. }
  99. }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement