Advertisement
nevenailievaa

09.PadawanEquipmentEdited

Jan 14th, 2023
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.39 KB | None | 0 0
  1. // input
  2. double money = double.Parse(Console.ReadLine()!);
  3. int students = int.Parse(Console.ReadLine()!);
  4. double lightsaberPrice = double.Parse(Console.ReadLine()!);
  5. double robePrice = double.Parse(Console.ReadLine());
  6. double beltPrice = double.Parse(Console.ReadLine()!);
  7.  
  8. // • Lightsaber
  9. double lightsabers = Math.Ceiling((double)students * 1.10);  //Tук няма как да умножиш students по 1.10, тъй като е int, а не double, затова го правиш на double със скобите пред него най-просто
  10. double sumLightsabers = lightsabers * lightsaberPrice;
  11.  
  12. //   Robe
  13. double sumRobes = students * robePrice;
  14.  
  15. // • Belt
  16. double belts = students;
  17. double sumBelts = belts * beltPrice;
  18.  
  19. //if (students >= 6)
  20. //{
  21. //    double beltsDiscount = belts / 6;
  22. //    sumBelts = (belts - beltsDiscount) * beltPrice;
  23. // Това не е правилно решение, това отдолу е:
  24.  
  25. double sixthBelts = Math.Floor((double) students / 6); // Така виждаш колко пъти имаш шести колан
  26. sumBelts = (students * beltPrice) - (sixthBelts * beltPrice);
  27.  
  28. // total
  29. double totalSum = sumRobes + sumLightsabers + sumBelts;
  30.  
  31. if (totalSum <= money)
  32. {
  33.     Console.WriteLine($"The money is enough - it would cost {totalSum:f2}lv.");
  34. }
  35. else
  36. {
  37.     Console.WriteLine($"John will need {totalSum - money:f2}lv more.");
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement