Advertisement
Guest User

Untitled

a guest
Jun 11th, 2019
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace _02_BreadFactory
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. // (Demo) Technology Fundamentals Mid Exam - 02 March 2019
  11.  
  12. string[] inputCases = Console.ReadLine().Split("|");
  13.  
  14. int energy = 100;
  15. int coins = 100;
  16.  
  17. for (int i = 0; i < inputCases.Length; i++)
  18. {
  19. string[] currentCase = inputCases[i].Split("-");
  20.  
  21. string command = currentCase[0];
  22. int value = int.Parse(currentCase[1]);
  23.  
  24. switch (command)
  25. {
  26. case "rest":
  27.  
  28. energy += value;
  29. if (energy >100 )
  30. {
  31. energy = 100;
  32. value = 0;
  33. }
  34. Console.WriteLine($"You gained {value} energy.");
  35. Console.WriteLine($"Current energy: {energy}.");
  36.  
  37. break;
  38.  
  39. case "order":
  40. energy -= 30;
  41.  
  42. if (energy < 0)
  43. {
  44. energy += 80; // energy += 50;
  45. Console.WriteLine("You had to rest!");
  46. }
  47. else
  48. {
  49. coins += value;
  50. //energy -= 30;
  51. Console.WriteLine($"You earned {value} coins.");
  52. }
  53. break;
  54.  
  55. default:
  56. if (coins > value) // Π’ΡƒΠΊΠ°
  57. {
  58. Console.WriteLine($"You bought {command}.");
  59. coins -= value;
  60. }
  61. else
  62. {
  63. Console.WriteLine($"Closed! Cannot afford {command}.");
  64. return;
  65. }
  66. break;
  67. }
  68. }
  69.  
  70. Console.WriteLine("Day completed!");
  71. Console.WriteLine($"Coins: {coins}");
  72. Console.WriteLine($"Energy: {energy}");
  73. }
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement