Advertisement
Stan0033

Untitled

Jul 9th, 2021
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace apps
  6. {
  7. class Program
  8. {
  9. static double GetDouble() { return double.Parse(Console.ReadLine()); }
  10. static int GetInt() { return int.Parse(Console.ReadLine()); }
  11.  
  12. static void Main()
  13. {
  14. int DAYS_AT_SEA = GetInt();
  15. int DAILY_PLUNDER = GetInt();
  16. double EXPECTED_PLUNDER = GetDouble();
  17. double TOTAL_PLUNDER = 0;
  18.  
  19. // calculate how much the pirates gather
  20. // each day they gather plunder
  21. // every 1/3 day they attack more ships and add more plunder = /2 daily_plunder
  22. // every 1/5 they lose 30% of total plunder
  23. // if plunder >= total -> "Ahoy! {totalPlunder} plunder gained."
  24. // else -> "Collected only {percentage}% of the plunder."
  25. for (int i =1; i<= DAYS_AT_SEA; i++)
  26. {
  27. if (i% 3 == 0)
  28. {
  29. double ADDITIONAL_PLUNDER = DAILY_PLUNDER / 2;
  30.  
  31. TOTAL_PLUNDER += (double)DAILY_PLUNDER + (double)ADDITIONAL_PLUNDER;
  32. continue;
  33. }
  34. if (i % 5 == 0)
  35. {
  36. TOTAL_PLUNDER += (double) DAILY_PLUNDER;
  37. TOTAL_PLUNDER *= 0.70;
  38.  
  39. continue;
  40. }
  41.  
  42. TOTAL_PLUNDER += DAILY_PLUNDER;
  43. }
  44. //---------------------------------------------------------
  45. if (TOTAL_PLUNDER>= EXPECTED_PLUNDER)
  46. {
  47. Console.WriteLine($"Ahoy! {TOTAL_PLUNDER:f2} plunder gained.");
  48. }
  49. else
  50. {
  51. double percentage = (TOTAL_PLUNDER*100)/EXPECTED_PLUNDER;
  52. Console.WriteLine($"Collected only { percentage:f2}% of the plunder.");
  53. }
  54. }
  55. }
  56. }
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement