Advertisement
Guest User

Untitled

a guest
May 22nd, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.29 KB | None | 0 0
  1. using System;
  2.  
  3. namespace zad7
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. string input = Console.ReadLine();
  10. double Sum = 0;
  11.  
  12. while (input != "Start")
  13. {
  14. double coins = double.Parse(input);
  15.  
  16. if (coins == 0.1)
  17. {
  18. Sum += 0.1;
  19. } else if (coins == 0.2) {
  20. Sum += 0.2;
  21. } else if (coins == 0.5)
  22. {
  23. Sum += 0.5;
  24.  
  25. } else if (coins == 1)
  26. {
  27. Sum += 1;
  28. } else if (coins == 2)
  29. {
  30. Sum += 2;
  31. } else
  32. {
  33. Console.WriteLine($"Cannot accept {coins:f1}");
  34. }
  35. input = Console.ReadLine();
  36. }
  37. input = Console.ReadLine();
  38.  
  39. while (input != "End")
  40. {
  41. double testSum = Sum;
  42. if (input == "Nuts")
  43. {
  44. testSum -= 2;
  45. if (testSum < 0)
  46. {
  47. Console.WriteLine("Sorry, not enough money");
  48. } else
  49. {
  50. Console.WriteLine("Purchased nuts");
  51. Sum = testSum;
  52. }
  53. } else if (input == "Water")
  54. {
  55. testSum -= 0.7;
  56. if (testSum < 0)
  57. {
  58. Console.WriteLine("Sorry, not enough money");
  59. } else
  60. {
  61. Console.WriteLine("Purchased water");
  62. Sum = testSum;
  63. }
  64. } else if (input == "Crisps")
  65. {
  66. testSum -= 1.5;
  67. if (testSum < 0)
  68. {
  69. Console.WriteLine("Sorry, not enough money");
  70. } else
  71. {
  72. Console.WriteLine("Purchased crisps");
  73. Sum = testSum;
  74. }
  75. } else if (input == "Soda")
  76. {
  77. testSum -= 0.8;
  78. if (testSum < 0)
  79. {
  80. Console.WriteLine("Sorry, not enough money");
  81. } else
  82. {
  83. Console.WriteLine("Purchased soda");
  84. Sum = testSum;
  85. }
  86. } else if (input == "Coke")
  87. {
  88. testSum -= 1;
  89. if (testSum < 0)
  90. {
  91. Console.WriteLine("Sorry, not enough money");
  92. } else
  93. {
  94. Console.WriteLine("Purchased coke");
  95. Sum = testSum;
  96. }
  97. } else
  98. {
  99. Console.WriteLine("Invalid product");
  100. }
  101. input = Console.ReadLine();
  102. }
  103. Console.WriteLine($"Change: {Sum:f2}");
  104.  
  105. }
  106. }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement