Advertisement
Guest User

Untitled

a guest
Jan 21st, 2020
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.69 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 totalPrice = 0;
  10. string moneyInput = Console.ReadLine();
  11.  
  12.  
  13.  
  14. while (moneyInput != "Start")
  15. {
  16. double moneyInputValue = double.Parse(moneyInput);
  17. if (moneyInput == "0,1" || moneyInput == "0,2" || moneyInput == "0,5" || moneyInput == "1" || moneyInput == "2")
  18. {
  19.  
  20. totalPrice += moneyInputValue;
  21.  
  22. }
  23. else
  24. {
  25. Console.WriteLine($"Cannot accept {moneyInputValue}");
  26. }
  27. moneyInput = Console.ReadLine();
  28. }
  29.  
  30.  
  31.  
  32. string product = Console.ReadLine();
  33. double productPrice = 0;
  34.  
  35.  
  36. while (product != "End")
  37. {
  38. bool verify = false;
  39. string purchased = "";
  40.  
  41. if (product == "Nuts")
  42. {
  43. productPrice = 2;
  44. purchased = "Purchased nuts";
  45. }
  46. else if (product == "Water")
  47. {
  48. productPrice = 0.7;
  49. purchased = "Purchased water";
  50. }
  51. else if (product == "Crisps")
  52. {
  53. productPrice = 1.5;
  54. purchased = "Purchased crisps";
  55. }
  56. else if (product == "Soda")
  57. {
  58. productPrice = 0.8;
  59. purchased = "Purchased soda";
  60. }
  61. else if (product == "Coke")
  62. {
  63. productPrice = 1;
  64. purchased = "Purchased coke";
  65. }
  66. else
  67. {
  68. Console.WriteLine("Invalid product");
  69. verify = true;
  70. product = Console.ReadLine();
  71. }
  72.  
  73. if (verify == false)
  74. {
  75. if (totalPrice >= productPrice)
  76. {
  77. Console.WriteLine(purchased);
  78. totalPrice -= productPrice;
  79. product = Console.ReadLine();
  80. }
  81. else
  82. {
  83. Console.WriteLine("Sorry, not enough money");
  84. product = Console.ReadLine();
  85. }
  86. }
  87.  
  88. }
  89.  
  90. Console.WriteLine($"Change: {totalPrice:F2}");
  91.  
  92. }
  93. }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement