Advertisement
Guest User

Untitled

a guest
May 15th, 2023
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. namespace _07._Vending_Machine
  2. {
  3. internal class Program
  4. {
  5. static void Main(string[] args)
  6. {
  7. string input = (Console.ReadLine());
  8. double currentSum = 0;
  9. while (input != "Start")
  10. {
  11. double coin = double.Parse(input);
  12. switch (coin)
  13. {
  14. case 0.2: currentSum += coin; break;
  15. case 0.1: currentSum += coin; break;
  16. case 0.5: currentSum += coin; break;
  17. case 1: currentSum += coin; break;
  18. case 2: currentSum += coin; break;
  19. default:Console.WriteLine($"Cannot accept {coin}");break;
  20. }
  21. input = Console.ReadLine();
  22. }
  23. string product = Console.ReadLine();
  24. while (product != "End")
  25. {
  26. double productCost = 0;
  27. switch (product)
  28. {
  29. case "Nuts": productCost = 2; break;
  30. case "Water": productCost = 0.7; break;
  31. case "Crisps": productCost = 1.5; break;
  32. case "Soda": productCost = 0.8; break;
  33. case "Coke": productCost = 1; break;
  34. default:Console.WriteLine($"Invalid product"); break;
  35.  
  36. }
  37. if (currentSum >= productCost && currentSum > 0 && productCost > 0)
  38. {
  39. currentSum -= productCost;
  40. Console.WriteLine($"Purchased {product.ToLower()}");
  41. }
  42. else if (productCost > 0)
  43. {
  44. Console.WriteLine($"Sorry, not enough money");
  45. }
  46. product = Console.ReadLine();
  47. }
  48. Console.WriteLine($"Change: {currentSum:f2}");
  49. }
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement