Advertisement
Guest User

Untitled

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