Advertisement
VDimov01

Untitled

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