Advertisement
Guest User

Untitled

a guest
Sep 24th, 2018
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data.SqlTypes;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace vendingMachine
  9. {
  10. class Program
  11. {
  12. static void Main(string[] args)
  13. {
  14. string money;
  15. decimal wallet = 0;
  16. string product;
  17. Dictionary<string,decimal> assortment = new Dictionary<string, decimal>()
  18. {
  19. {"nuts",(decimal)2.0},
  20. {"water",(decimal)0.7},
  21. {"crisps",(decimal)1.5},
  22. {"soda",(decimal)0.8},
  23. {"coke",(decimal)1.0}
  24. };
  25.  
  26. decimal[] coins = new decimal[] {(decimal)0,1,(decimal)0.2, (decimal)0.5, (decimal)1, (decimal)0.2, (decimal)2 };
  27.  
  28. money = Console.ReadLine().ToLower();
  29.  
  30. while(money != "start")
  31. {
  32. if (coins.Contains(decimal.Parse(money)))
  33. {
  34. wallet += decimal.Parse(money);
  35. }
  36. else
  37. {
  38. Console.WriteLine($"Cannot accept {money}");
  39. }
  40.  
  41. money = Console.ReadLine().ToLower();
  42. }
  43.  
  44. product = Console.ReadLine().ToLower();
  45.  
  46.  
  47. while (product != "end")
  48. {
  49.  
  50. if (assortment.ContainsKey(product))
  51. {
  52. if (wallet >= assortment[product])
  53. {
  54. Console.WriteLine($"Purchased {product}");
  55. wallet -= assortment[product];
  56. }
  57. else
  58. {
  59. Console.WriteLine("Sorry, not enough money");
  60. }
  61. }
  62. else
  63. {
  64. Console.WriteLine("Invalid product");
  65. }
  66. product = Console.ReadLine().ToLower();
  67. }
  68.  
  69. Console.WriteLine($"Change: {wallet:F2}");
  70.  
  71. }
  72. }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement