Advertisement
ralichka

05.More.Exercises.For.Loop-03.Logistics

Jul 12th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.58 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _03.Logistics
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int count = int.Parse(Console.ReadLine());
  10.  
  11.             double price = 0;
  12.             double p1 = 0;
  13.             double p2 = 0;
  14.             double p3 = 0;
  15.             double p1Percent = 0;
  16.             double p2Percent = 0;
  17.             double p3Percent = 0;
  18.  
  19.             double totalWeight = 0;
  20.            
  21.  
  22.             for (int i = 0; i < count; i++)
  23.             {
  24.                 int weight = int.Parse(Console.ReadLine());
  25.  
  26.  
  27.                 if (weight <= 3)
  28.                 {
  29.                     price += weight*200;
  30.                     p1 += weight;
  31.                    
  32.                 }
  33.                 else if (weight<=11)
  34.                 {
  35.                     price +=weight*175;
  36.                     p2 += weight;
  37.                    
  38.                 }
  39.                 else if (weight >= 12)
  40.                 {
  41.                     price +=weight*120;
  42.                     p3 += weight;
  43.                    
  44.                 }
  45.                 totalWeight = p1 + p2 + p3;
  46.                 p1Percent = p1 / totalWeight * 100;
  47.                 p2Percent = p2 / totalWeight * 100;
  48.                 p3Percent = p3 / totalWeight * 100;
  49.  
  50.             }
  51.             double average = price / totalWeight;
  52.  
  53.             Console.WriteLine($"{average:f2}");
  54.             Console.WriteLine($"{p1Percent:f2}%");
  55.             Console.WriteLine($"{p2Percent:f2}%");
  56.             Console.WriteLine($"{p3Percent:f2}%");
  57.            
  58.         }
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement