Advertisement
MZlatev

Dishwasher

Jul 5th, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.65 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _1._1_DishwasherVariation
  4.  
  5. {
  6. class Program
  7. {
  8. static void Main()
  9. {
  10. int detergent = int.Parse(Console.ReadLine());
  11.  
  12.  
  13. int totalDetergent = detergent * 750; //за прегледност и по-лесна употреба
  14.  
  15. int containers = 0; //съдове
  16.  
  17. int dishes = 0; //numOfPlates
  18. int dishesDetergent = 0; //spentDetergentInwashedPlates
  19.  
  20. int pots = 0; //numOfPots
  21. int potsDetergent = 0; //spentDetergentInWashedPots
  22.  
  23. int counter = 1; //// забравил си да си направиш брояч, който ще ни е необходим за модулното делене по-долу.
  24.  
  25. //int difference = 0; // - все още не ти е нужно. Даже не съм сигурен дали изобщо ще е нужно. Може би в логиката, която ще разпиша е излишно.
  26.  
  27. string command = Console.ReadLine(); //numOfContainers
  28.  
  29.  
  30. while (command != "End")
  31. {
  32. containers = int.Parse(command);
  33.  
  34. //тук е нужно на всяко трето зареждане със съдове, съдомиялната да се пълни само с тенджери, а останалите пъти с чинии. За целта използваме модулно делене.
  35.  
  36. if (counter % 3 == 0)
  37. {
  38. potsDetergent = containers * 15;
  39. totalDetergent -= potsDetergent; //allDeterget = allDetergent - potsDetergent;
  40. pots += containers; // pots = pots + containers;
  41. }
  42.  
  43. else
  44. {
  45. dishesDetergent = containers * 5;
  46. totalDetergent -= dishesDetergent;
  47. dishes += containers;
  48. }
  49.  
  50. //allDetergent = dishesDetergent + potsDetergent; - не е нужно тъй като с по-горната логика то автоматично се събира. Първите две въвеждания (command в твоя случай) ги приема за чинии (понеже не отговаря на модулното делене) и ги прибавя към AllDetergent, а при третото въвеждане го приема за тенджера и отново прибавя към AllDetergent :)
  51.  
  52.  
  53. if (totalDetergent < 0)
  54. {
  55. Console.WriteLine($"Not enough detergent, {Math.Abs(totalDetergent)} ml. more necessary!");
  56. return; //return излиза изцяло от static void Main() и това ще е последното, което ще се изпълни. Ако бяхме използвали "break" това щеше да е последният изпълнене ред от цикъла, но щеше да ни изведе след цикъла, а ние там използваме друга логика и не искаме накрая в конзолата да ни се отпечатват и двете логики едновременно :)
  57. }
  58.  
  59. command = Console.ReadLine();
  60. counter++;
  61.  
  62. }
  63.  
  64. //if (command == "End" && detergent >= allDetergent)
  65. //{
  66. // difference = detergent - allDetergent;
  67. // Console.WriteLine("Detergent was enough!");
  68. // Console.WriteLine($"{dishes} dishes and {pots} pots were washed.");
  69. // Console.WriteLine($"Leftover detergent {difference} ml.");
  70. //}
  71.  
  72. //else if (command == "End" && detergent < allDetergent)
  73. //{
  74. // difference = allDetergent - detergent;
  75. // Console.WriteLine($"Not enough detergent, {difference} ml. more necessary!");
  76. //}
  77.  
  78. //else
  79. //{
  80. // difference = allDetergent - detergent;
  81. // Console.WriteLine($"Not enough detergent, {difference} ml. more necessary!");
  82. //} - това ти е излишно, можеш да го изтриеш
  83.  
  84. Console.WriteLine($"Detergent was enough!");
  85. Console.WriteLine($"{dishes} dishes and {pots} pots were washed.");
  86. Console.WriteLine($"Leftover detergent {totalDetergent} ml.");
  87.  
  88. }
  89. }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement