TheBulgarianWolf

Orders

Mar 3rd, 2021
754
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.44 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace Orders
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             Console.WriteLine("Start entering your products: ");
  11.             string input;
  12.             Dictionary<string, double> productPrices = new Dictionary<string, double>();
  13.             Dictionary<string, int> productQuantity = new Dictionary<string, int>();
  14.             while ((input = Console.ReadLine()) != "buy")
  15.             {
  16.                 string[] inputArr = input.Split();
  17.                 string productName = inputArr[0];
  18.                 double productPrice = double.Parse(inputArr[1]);
  19.                 int quantity = int.Parse(inputArr[2]);
  20.                 if (productPrices.ContainsKey(productName))
  21.                 {
  22.                     if(productPrices[productName] < productPrice)
  23.                     {
  24.                         productPrices[productName] = productPrice;
  25.                         productQuantity[productName] += quantity;
  26.                     }
  27.                 }
  28.                 else
  29.                 {
  30.                     productPrices.Add(productName, productPrice);
  31.                     productQuantity.Add(productName, quantity);
  32.                 }
  33.             }
  34.  
  35.             foreach(var item in productPrices)
  36.             {
  37.                 Console.WriteLine("{0} -> {1:F2}", item.Key,(item.Value*productQuantity[item.Key]));
  38.             }
  39.         }
  40.     }
  41. }
  42.  
Add Comment
Please, Sign In to add comment