petarkobakov

Report system

Feb 26th, 2020
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Report_System
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. int moneyNeeded = int.Parse(Console.ReadLine());
  10. string command = Console.ReadLine();
  11. int transaction = 0;
  12. int cashTrans = 0;
  13. int cardTrans = 0;
  14. int totalCash = 0;
  15. int totalCard = 0;
  16. int sumOfdonations = 0;
  17.  
  18.  
  19. while (command != "End")
  20. {
  21. int price = int.Parse(command);
  22. transaction++;
  23.  
  24. if (moneyNeeded > sumOfdonations)
  25. {
  26. if (transaction % 2 == 0)
  27. {
  28. if (price >= 10)
  29. {
  30. cardTrans++;
  31. totalCard += price;
  32. sumOfdonations += price;
  33.  
  34. Console.WriteLine("Product sold!");
  35. }
  36. else
  37. {
  38. Console.WriteLine("Error in transaction!");
  39. }
  40.  
  41. }
  42. else
  43. {
  44. if (price <= 100)
  45. {
  46. cashTrans++;
  47. totalCash += price;
  48. sumOfdonations += price;
  49.  
  50. Console.WriteLine("Product sold!");
  51. }
  52. else
  53. {
  54. Console.WriteLine("Error in transaction!");
  55. }
  56. }
  57.  
  58. if (command == "End" || moneyNeeded <= sumOfdonations)
  59. {
  60.  
  61. break;
  62. }
  63. }
  64. command = Console.ReadLine();
  65. }
  66.  
  67. if (sumOfdonations >= moneyNeeded)
  68. {
  69. double averageCS = (double)totalCash / cashTrans;
  70. double averageCC = (double)totalCard / cardTrans;
  71.  
  72. Console.WriteLine($"Average CS: {averageCS:f2}");
  73. Console.WriteLine($"Average CC: {averageCC:f2}");
  74. }
  75. else
  76. {
  77. Console.WriteLine("Failed to collect required money for charity.");
  78. }
  79. }
  80. }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment